Association data within a fields_for

zindelo
Tue, 01 Mar 2011 19:31:55 -0000

How do I use association data from within a fields_for?

I''ve got a has many through relationship between users, schools and
schools_users. A user can have multiple schools and a school has multiple
users. In schools_users there is a user_role field in addition to the common
user_id and school_id.

In the show view I have:

<% @school.schools_users.each do |user| %>
<%= user.user.first_name %> <%= user.user.last_name
%> <%=
user.user_role %>
<% end %>

but I can''t figure out how to do the same thing from within the
fields_for
on the edit page.

<%= f.fields_for :schools_users do |f| %>

<%= NEED USER NAME HERE %>
<%= f.select(:user_role, active_role_options)%>
<%= link_to_remove_fields ''Delete'', f
%>

<% end %>

Thanks for any help!

--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at