开发者

Get a value of object field inside fields_for loop

开发者 https://www.devze.com 2023-02-01 10:57 出处:网络
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| %>

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消