I have just started using RoR and am creating some select boxes on my form with the following code: <%= select_tag(options_from_collection_for_select(Owner.all, :id, :fname)) %> My problem is that it does NOT return the first record from the table, but just the second and succeeding records. Does anyone have any ideas on how I can get the first record included in the select box? 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/hRk-fSwUgWIJ. For more options, visit https://groups.google.com/groups/opt_out.
On 18 January 2013 12:19, Gerry Brown <gerbreown1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have just started using RoR and am creating some select boxes on my form > with the following code: > <%= select_tag(options_from_collection_for_select(Owner.all, :id, :fname)) > %> > My problem is that it does NOT return the first record from the table, but > just the second and succeeding records.Check the docs for select_tag and you will see that you are missing the first parameter. Perhaps you meant to use f.select, which is generally the right way to do it. For the future have a look at the Rails Guide on debugging which will show you techniques that you can use to debug your code. Colin -- 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 https://groups.google.com/groups/opt_out.
On Friday, January 18, 2013 8:19:14 PM UTC+8, Gerry Brown wrote:> > I have just started using RoR and am creating some select boxes on my form > with the following code: > <%= select_tag(options_from_collection_for_select(Owner.all, :id, :fname)) > %> > My problem is that it does NOT return the first record from the table, but > just the second and succeeding records. > Does anyone have any ideas on how I can get the first record included in > the select box? > Thanks. >I changed the above code to: "<%= select_tag(collection_select(:book, :owner_id, Owner.all, :id, :full_name)) %>" and now it gets all records as it should. -- 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Qo2ua_G6qXEJ. For more options, visit https://groups.google.com/groups/opt_out.