Forum: Ruby on Rails options_from_collection_for_select

Posted by Gerry Brown (Guest)
on 2013-01-18 13:34
(Received via mailing list)
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.
Posted by Colin Law (Guest)
on 2013-01-18 14:48
(Received via mailing list)
On 18 January 2013 12:19, Gerry Brown <gerbreown1@gmail.com> 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
Posted by Gerry Brown (Guest)
on 2013-01-19 12:33
(Received via mailing list)
On Friday, January 18, 2013 8:19:14 PM UTC+8, Gerry Brown wrote:
>
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.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.