Follow-up, in the nested form if I have:
<div class="field">
<%= item.label :recipient_id %>
<%= item.text_field :recipient_id %>
<%= item.check_box :recipient_id %>
</div>
I get an output of
<div class="field">
<label
for="request_thread_requests_attributes_1_recipient_id">Recipient</
label>
<input id="request_thread_requests_attributes_1_recipient_id"
name="request_thread[requests_attributes][1][recipient_id]" size="30"
type="text" value="61">
<input name="request_thread[requests_attributes][1][recipient_id]"
type="hidden" value="0"><input checked="checked"
id="request_thread_requests_attributes_1_recipient_id"
name="request_thread[requests_attributes][1][recipient_id]"
type="checkbox" value="1">
</div>
So the ID I want is working for text_field but not check_box
On Nov 10, 7:50 pm, CuriousNewbie <[email protected]> wrote:
> Hello, I have the following:
>
> My Controller:
>
> def new
> .
> .
> @teammembers.each do |teammember|
> request = @request_thread.requests.build(:recipient_id =>
> teammember.user_id, :full_name => 'Billy Bob T')
> end
>
> My View:
> .
> .
> <%= f.fields_for :requests do |builder| %>
>
> <div class="field">
> <%= builder.label :full_name %>
> <%= builder.check_box :recipient_id, :checked =>
> false %>
> </div>
> <% end %>
> .
> .
> The nested form for requests only holds the user_id, not the
> user.name... Problem is in the nested form, I need to show the
> user.name next to the check_box. So I tried adding a virtual attribute
> in the model (attr_accessor :full_name), so I could use full_name but
> I can't see to access that in the nested form (inside builder).
>
> Also, the checkbox doesn't have the recipient_id as the value being
> set? I want to use the checkbox to tell Rails whether or not to create
> the record or not on submit using something like this in the model
> ":reject_if => lambda { |a| a[:recipient_id].blank? }"
>
> Anyone with fields_for experience?
>
> Any tips or suggestions from the pros?
>
> Thanks
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.