Comments on: Dynamic Select Boxes – Ruby on Rails 3 http://pullmonkey.com/2012/08/11/dynamic-select-boxes-ruby-on-rails-3/ Tue, 05 Feb 2013 04:29:28 +0000 hourly 1 https://wordpress.org/?v=5.6 By: `Drew http://pullmonkey.com/2012/08/11/dynamic-select-boxes-ruby-on-rails-3/comment-page-1/#comment-24291 Tue, 05 Feb 2013 04:29:28 +0000 http://pullmonkey.com/?p=57726#comment-24291 First of all, thanks for this. It has been an excellent teaching tool for the collection_select dropdown box method for me. That being said, I’m stuck. My dropdown menus aren’t populated with any data! I followed the tutorial exactly the first two times through. THEN I copied and pasted your code to make sure it wasn’t my mistyping that had screwed things up. No luck still. Any suggestions for where my hangup might be?

]]>
By: Bardach http://pullmonkey.com/2012/08/11/dynamic-select-boxes-ruby-on-rails-3/comment-page-1/#comment-24290 Thu, 31 Jan 2013 02:57:00 +0000 http://pullmonkey.com/?p=57726#comment-24290 Hi Charlie,
Thanks for this useful tutorial.
How can use it with simple_form?
Bardach

]]>
By: Bardach http://pullmonkey.com/2012/08/11/dynamic-select-boxes-ruby-on-rails-3/comment-page-1/#comment-24289 Thu, 31 Jan 2013 02:56:40 +0000 http://pullmonkey.com/?p=57726#comment-24289 Hi Charlie,
Thanks for this useful tutorial.
How can used it with simple_form?
Bardach5

]]>
By: charlie http://pullmonkey.com/2012/08/11/dynamic-select-boxes-ruby-on-rails-3/comment-page-1/#comment-19235 Wed, 05 Sep 2012 13:56:53 +0000 http://pullmonkey.com/?p=57726#comment-19235 In reply to Bob Hazlewood.

You can do this many ways.
1) In the models: You can set the default order of all the models. Plus for the has_many associations, you could add an order clause: has_many :songs, :order => :title
2) In the controller: Instead of Genre.all, you would do Genre.order(:name), or instead of artist.songs, you would do artist.songs.order(:title)

Then the map just acts on the ordered collection.

]]>
By: Bob Hazlewood http://pullmonkey.com/2012/08/11/dynamic-select-boxes-ruby-on-rails-3/comment-page-1/#comment-19108 Wed, 29 Aug 2012 05:05:16 +0000 http://pullmonkey.com/?p=57726#comment-19108 hahaha back again with another question.

In your example, the elements come back in the order in which they are in the database (song1, then song2, then song3). Of course, in the “real world” the data would be more like “Good Vibrations”, “Surfer Girl”, and “I Get Around”. What if you want the select list to be in alphabetical order? Normally I would pull the data like @songs = Song.find(:all, :order => ‘title ASC’) – how would you do that with the .map?

]]>
By: Bob Hazlewood http://pullmonkey.com/2012/08/11/dynamic-select-boxes-ruby-on-rails-3/comment-page-1/#comment-19041 Tue, 21 Aug 2012 16:28:00 +0000 http://pullmonkey.com/?p=57726#comment-19041 I figured it out.

When I select the third element, it executes a render partial with a link_to , :controller => ‘controller_name’, :action => ‘action_name’, :parameter1 => params[:select_name1], :parameter2 => params[:select_name2]

Thanks again for a great learning tool.

]]>
By: Bob Hazlewood http://pullmonkey.com/2012/08/11/dynamic-select-boxes-ruby-on-rails-3/comment-page-1/#comment-19034 Mon, 20 Aug 2012 21:49:11 +0000 http://pullmonkey.com/?p=57726#comment-19034 I know this is beyond the scope of your tutorial, but — let’s say I want to take the results of all three selects, and pass those as parameters to a controller? On the final select, render a partial with the params ?

]]>
By: charlie http://pullmonkey.com/2012/08/11/dynamic-select-boxes-ruby-on-rails-3/comment-page-1/#comment-19020 Thu, 16 Aug 2012 23:41:55 +0000 http://pullmonkey.com/?p=57726#comment-19020 In reply to Foluso.

Thanks Foluso, updated post with the converted erb – at the bottom.

]]>
By: Foluso http://pullmonkey.com/2012/08/11/dynamic-select-boxes-ruby-on-rails-3/comment-page-1/#comment-19019 Thu, 16 Aug 2012 21:02:45 +0000 http://pullmonkey.com/?p=57726#comment-19019 Thank you very much Charlie for your help. I eventually got it to work though I had to adjust the following files too

# app/views/home/update_artists.js.erb
$(‘#artists_select’).html(“”);
$(‘#songs_select’).html(“”);

# app/views/home/update_songs.js.erb
$(‘#songs_select’).html(“”);

]]>
By: charlie http://pullmonkey.com/2012/08/11/dynamic-select-boxes-ruby-on-rails-3/comment-page-1/#comment-19018 Thu, 16 Aug 2012 03:57:25 +0000 http://pullmonkey.com/?p=57726#comment-19018 Foluso – the only file you’ll want to convert to use erb is going to be the index.html.haml.
The others, you can just rename to .js.erb.

For the index.html.erb, just wrap the lines starting with “=” with <% and %>
And instead of :javascript, just wrap with .

I’ve updated the post to have the erb example for that file.

]]>