Created
February 2, 2011 19:19
-
-
Save CootCraig/808211 to your computer and use it in GitHub Desktop.
Rails nonmodel select
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= 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. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= 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+'' + '&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