Skip to content

Instantly share code, notes, and snippets.

@CootCraig
Created February 2, 2011 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CootCraig/808211 to your computer and use it in GitHub Desktop.
Save CootCraig/808211 to your computer and use it in GitHub Desktop.
Rails nonmodel select
= 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.
= 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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment