public
Last active

Rails nonmodel select

  • Download Gist
first success
1 2 3 4 5 6 7 8 9 10 11
= select_tag('tweet_source', options_for_select([['',0],['My Tweets',1],['Retweets',2],['Favorites',3],['Mentions',4]],2), {})
 
<select name="tweet_source" id="tweet_source"><option value="0"></option>
<option value="1">My Tweets</option>
<option selected="selected" value="2">Retweets</option>
<option value="3">Favorites</option>
<option value="4">Mentions</option></select>
 
Want the onchange event to GET on tweets controller index action with tweet_source in params.
 
Looking for the rails (2.3) way to do this. The option source is a collection, not a model.
onchange working yippee
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
= select_tag('tweet_source', options_for_select([['',0],['My Tweets',1],['Retweets',2],['Favorites',3],['Mentions',4]],2),{:onchange => remote_function(:url => {:action => 'index'}, :with => "'tweet_source='+this.value+''", :method => 'get')})
 
 
<select onchange="new Ajax.Request('/', {asynchronous:true, evalScripts:true, method:'get', parameters:'tweet_source='+this.value+'' + '&amp;authenticity_token=' + encodeURIComponent('84XCR3wF7cDiG6gQlzrcomqRlgLUUJ/4UzbOLs14mOA=')})" name="tweet_source" id="tweet_source"><option value="0"></option>
<option value="1">My Tweets</option>
<option selected="selected" value="2">Retweets</option>
<option value="3">Favorites</option>
<option value="4">Mentions</option></select>
 
 
=== Sure enough, correct parameters being sent onchange
 
Completed in 41ms (View: 16, DB: 16) | 200 OK [http://localhost/?tweet_source=2&authenticity_token=84XCR3wF7cDiG6gQlzrcomqRlgLUUJ%2F4UzbOLs14mOA%3D]
 
Completed in 48ms (View: 17, DB: 17) | 200 OK [http://localhost/?tweet_source=4&authenticity_token=84XCR3wF7cDiG6gQlzrcomqRlgLUUJ%2F4UzbOLs14mOA%3D]

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.