Using search_field as select

96 views
Skip to first unread message

Alexandre Balon-Perin

unread,
Jan 28, 2012, 2:06:31 PM1/28/12
to Ruby on Rails: Talk
Hi,

I am trying to make the search_field look into a table of my database
which is different from the form's object's table.
Basically, I want to do this:

<td><%= f.search_field(:sport, Sport.all.collect {|s|[s.sport_name]})
%></td>

But it does not work obviously.

Sorry if this issue has already been raised but I did not find any
solution after searching on google and in this group posts.

Thank you in advance for your help,
Alex

Tim Shaffer

unread,
Jan 30, 2012, 11:30:44 AM1/30/12
to rubyonra...@googlegroups.com
What exactly are you trying to do? All that search_field does is create a HTML input with type="search"

If you want a dropdown you should use collection_select or something similar

Alexandre Balon-Perin

unread,
Jan 30, 2012, 11:40:02 AM1/30/12
to rubyonra...@googlegroups.com
Hi,

Thank you for your reply.
I solved my problem using Custom Form Builder. I created a custom form field for the new HTML5 datalist. If anyone is interested, I can post my solution which is definitely not optimal since I am new to rails.

regards,
Alexandre

On 30 January 2012 17:30, Tim Shaffer <timsh...@me.com> wrote:
What exactly are you trying to do? All that search_field does is create a HTML input with type="search"

If you want a dropdown you should use collection_select or something similar

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/5Kke2y_WvhMJ.

To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Javier Quarite

unread,
Jan 30, 2012, 11:59:57 AM1/30/12
to rubyonra...@googlegroups.com
On Mon, Jan 30, 2012 at 11:40 AM, Alexandre Balon-Perin <abal...@ulb.ac.be> wrote:
Hi,

Thank you for your reply.
I solved my problem using Custom Form Builder. I created a custom form field for the new HTML5 datalist. If anyone is interested, I can post my solution which is definitely not optimal since I am new to rails.

regards,
Alexandre


I'm also doing some searchs using fields, I used the autocomplete method of jquery (I saw that in a railscast) 


Alexandre Balon-Perin

unread,
Jan 30, 2012, 12:38:07 PM1/30/12
to rubyonra...@googlegroups.com
@Javier:
I also watched the railscast but I prefer a "Ruby solution".
The custom form builder is simple and very readable so I am gonna stick with it. :)

Anyway thank you for your reply, I appreciate it.
Alex

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
Reply all
Reply to author
Forward
0 new messages