Basically what I''m trying to do is the Ruby/Rails equivalent of this:
<form action="../">
<select
onchange="window.open(''http://0.0.0.0:3000/artists/'' +
this.options[this.selectedIndex].value,''_top'')">
<option value="">Choose a destination...</option>
<option value="1">Artist 1</option>
<option value="2">Artist 2</option>
<option value="3">Artist 3</option>
<option value="4">Artist 4</option>
<option value="5">Artist 5</option>
<option value="6">Artist 6</option>
<option value="7">Artist 7</option>
<option value="8">Artist 8</option>
</select>
</form>
Here''s what I''ve come up with:
<% form_tag( "../") do %>
<%= collection_select(:artists, ''id'', @artists,
''id'', ''name'', {},
{:onchange =>
"window.open(''http://0.0.0.0:3000/artists/'' +
this.options[this.selectedIndex].value,''_top'')"}) %>
<% end %>
This works, I''m just not sure if it''s the best way. Anyone
have any
suggestions?
On Sep 21, 11:35 am, Chad W
<superw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I''m trying to figure out the best way to do this:
> I have an Artist model
> I want to create a dropdown list of all the artists in the database.
> When you select one of them form the list, you get redirected to their
> respective "show" action.
>
> In my routes.rb (using REST)
> map.resources :artists
>
> In my controller:
> @artists = Artist.find(:all, :order => "name")
>
> In my view:
> <% form_for(:artist, :url => artist_path(@artist), :html =>
{:method
> => :get}) do |f| %>
> <%= f.collection_select(''id'', @artists,
''id'', ''name'') %>
> <%= submit_tag "go!" %>
> <% end %>
>
> now, of course, this doesn''t work. When submitted, you just get
sent
> to the first @artist.id "show" action. I''ve been racking
my brain
> trying to figure out how to do this in Rails.
>
> Any help? Thanks much!
>
> -Chad
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---