CuriousNewbie
2010-Nov-11 03:50 UTC
Rails 3 - Nested Forms, using Builder -- Check_box issue
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 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 http://groups.google.com/group/rubyonrails-talk?hl=en.
CuriousNewbie
2010-Nov-11 03:53 UTC
Re: Rails 3 - Nested Forms, using Builder -- Check_box issue
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 <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
CuriousNewbie
2010-Nov-11 04:09 UTC
Re: Rails 3 - Nested Forms, using Builder -- Check_box issue
Shouldn''t this work: "<%= item.check_box :recipient_id, :value => :recipient_id %>" That outputs: <input checked="checked" id="request_thread_requests_attributes_1_recipient_id" name="request_thread[requests_attributes][1][recipient_id]" type="checkbox" value="1"> the value is wrong. All the checkboxes show value 1. Yet, this "<%item.text_field :recipient_id %>" gets the right value? On Nov 10, 7:53 pm, CuriousNewbie <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Possibly Parallel Threads
- How to Redirect from http://mysite.com to https://www.mysite.com on Herok
- Rails - JSON object with an array?
- This installation of RMagick was configured with ImageMagick 6.6.4 but ImageMagick 6.6.5-0 is in use
- test emails did not arrive at SMTP server : after dovecot installation
- check_box