In the following scenario, I need to check the value of the object property in the fields_for
loop.
<%= f.semantic_fields_for :review_details do |rd| %>
<%= rd.input :review_criteria_id, :as=>:hidden %>
<% end %>
As in the loop, :review_criteria_id
is rendered as hidden field, but I have a scenario, where I have to print some more information if it is a spec开发者_StackOverflowific criteria. How can I get the value of review_criteria_id
in the loop.
I used:
rd.review_criteria_id
But since rd
is the formtastic object, so I couldn't get the value of :review_crieteria_id
.
Formtastic adds additional features to the Rails code, but doesn't take away existing functionality so the following should work for you:
rd.object.review_criteria_id
'object' can be used in plain Rails form helpers to access the underlying bound object, and Formtastic honours this convention.
I got it, I can use
rd.object.review_criteria_id
object
is the default wrapper object for the fields_for
loop.
精彩评论