Ruby on Rails. Views in polymorphic associations
Add local variable:commentable => @article
, while rendering the commentaries form
<%= render 'commentaries/form', :commentable => @article %>
Access the local variable from you partial view views/commentaries/_form.html.erb
<% commentable.commentaries.each do |comment| %>
...
<% end %>
...
<% form_for [commentable, Comment.new] do |form| %>
...
<% end %>
How to get associated polymorphic objects in rails 5?
I'm not sure, but I think that AR doesn't provide a way to load polymorphic associations in just one query. But you can use:
post = Post.find(1)
post_followers = post.followers.includes(:owner)
post_owners = post_followers.map(&:owner)
Rails: includes with polymorphic association
This will hopefully be fixed in rails 5.0. There is already an issue and a pull request for it.
https://github.com/rails/rails/pull/17479
https://github.com/rails/rails/issues/8005
I have forked rails and applied the patch to 4.2-stable and it works for me. Feel free to use my fork, even though I cannot guarantee to sync with upstream on a regular basis.
https://github.com/ttosch/rails/tree/4-2-stable
RailsAdmin: polymorphic has_one association rendering in edit and list views
There's an option for that:
active true
About your second question, you may want to use the configure
verb instead of field
.
configure
won't interfere with the flow of default fields like field
does.
RailsAdmin has a project wiki. Whenever you find something that's not documented, you can add it there.
Related Topics
What's the Best Way to Return an Enumerator::Lazy When Your Class Doesn't Define #Each
Ruby or Rails Sort on Two/Multiple Date Fields
Ruby/Rails Array of Strings to Postgresql Insert
Bundle Exec Jekyll Serve: Cannot Load Such File
Ruby 'Gets' That Works Over Multiple Lines
Detecting Regional Settings (List Separator) from Web
What Does a Single Splat/Asterisk in a Ruby Argument List Mean
Array#Rotate Equivalent in Ruby 1.8.7
How to Specify a Struct as the Return Value of a Function in Rubyffi
Respond_With Redirect with Notice Flash Message Not Working
Controller Monkey Patch in Initializer Gets Lost When Rails Reloads Classes
Unable to Delete File from Amazon S3 Using Ruby Script
How to Figure Out Which Step I'Ve Just Executed in Cucumber's Afterstep Hook
Using Form_For Tag with Get Method
Svg Files in Raphael, Can They Be Used