Hi,
I''m new in developint rails (but I love rails).
I would like to react on changing a field in the view (no model field)
from a selection box to show the number of rows (which I used in the
controller).
In the controller I read the params-hash:
...
@rowsperpage = params[''rowsperpage''].to_i
...
In the view I have the field, where I like to react directly.
...
<%= select_tag("rowsperpage", options_for_select( [[5, 5],
[10,10],
[25,25], [50,50], [100,100],[200, 200],[500, 500],[1000, 1000]],
@rowsperpage ),
:onchange=>"alert(this.form.rowsperpage.options[this.form.rowsperpage.selectedIndex].value)"
) %>
...
The alert was only an example (I test it also with render, but without a
solution).
But I could change the values with no reaction.
What must I do, that the controller react direcly on my changes.
Thanks in advance.
Mike
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
mx wrote:> Hi, > > I''m new in developint rails (but I love rails). > I would like to react on changing a field in the view (no model field) > from a selection box to show the number of rows (which I used in the > controller). > > > In the controller I read the params-hash: > ... > @rowsperpage = params[''rowsperpage''].to_i > ... > > In the view I have the field, where I like to react directly. > ... > <%= select_tag("rowsperpage", options_for_select( [[5, 5], [10,10], > [25,25], [50,50], [100,100],[200, 200],[500, 500],[1000, 1000]], > @rowsperpage ), > :onchange=>"alert(this.form.rowsperpage.options[this.form.rowsperpage.selectedIndex].value)" > ) %> > ... > > The alert was only an example (I test it also with render, but without a > solution). > But I could change the values with no reaction. > What must I do, that the controller react direcly on my changes. > > Thanks in advance. > MikeTry searching the web for keywords remote_function and select_tag For example, this is close to what you want. <%= select_tag( :sort_by, options_for_select([["Sort by:",0],["Name",''name''],["Price",''price''], ["Date Listed",''id'']],0), :onchange => remote_function( :with => "''sort_by=''+$(\"sort_by\").value", :loading => "false;", :url => { :controller => ''products'', :action => :change_order } ) ) %> Stephan -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Try searching the web for keywords remote_function and select_tag > > For example, this is close to what you want. > > <%= select_tag( :sort_by, options_for_select([["Sort > by:",0],["Name",''name''],["Price",''price''], ["Date Listed",''id'']],0), > :onchange => remote_function( :with => > "''sort_by=''+$(\"sort_by\").value", > :loading => "false;", :url => { > :controller => ''products'', :action => :change_order } ) > ) %>I realize this is largely a question of taste, but wouldn''t Proper Rails Style prefer to invoke the remote function via the observe_field helper rather than the onchange attribute value? I ask in all sincerity, not having a great grasp yet of Proper Rails Style. - donald --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---