Pass selected value in combo as a parameter

13 views
Skip to first unread message

Alfredo Bonilla

unread,
Sep 3, 2010, 6:35:27 AM9/3/10
to rubyonra...@googlegroups.com
Hi,

I have a select in my form:

<%= select @issue_type, "name", @issue_types.collect {|p| [p.name,
p.id]} %>

What I need to do is execute a method passing the value selected in the
combo. I've tried lot of things, but I couldn't.

@issue_type is created in the controller and I assigned the first value
in the collection. Of course, this is the value I only can pass.

To retrieve the value in the combo I've tried with onchange, but... I
couldn't make it work

Thanks in advance
--
Posted via http://www.ruby-forum.com/.

Colin Law

unread,
Sep 4, 2010, 4:03:05 AM9/4/10
to rubyonra...@googlegroups.com
On 3 September 2010 11:35, Alfredo Bonilla <li...@ruby-forum.com> wrote:
> Hi,
>
> I have a select in my form:
>
> <%= select @issue_type, "name", @issue_types.collect {|p| [p.name,
> p.id]} %>
>
> What I need to do is execute a method passing the value selected in the
> combo. I've tried lot of things, but I couldn't.

Where are you trying to execute the method? In the browser or in the
server? If in the browser then you will have to use javascript (in
which case it is not really a Rails question), if in the server then
put the select in a form and the selected value will be passed in
params when the form is submitted.

Colin

Luke Cowell

unread,
Sep 4, 2010, 10:57:49 AM9/4/10
to Ruby on Rails: Talk
What I usually do is get things working without Ajax first. Assuming
you've done that, does onchange trigger anything in the logs? Using
firebug or the developer tools in chrome/safari could tell you a lot
too.

Luke

Alfredo Bonilla

unread,
Sep 6, 2010, 3:28:39 AM9/6/10
to rubyonra...@googlegroups.com
Again answering to myself...

I solved the problem by:

1-Using *link_to_remote* using :with clause, and passing as serialize
the id of the div that I had to create sourranding the select
2-In the controller, once taked the parm and maked all the operations,
use *respond_to* js and reloading the page.

Probably not the best solution... but it works!

Reply all
Reply to author
Forward
0 new messages