Skip to content

Instantly share code, notes, and snippets.

@maier-stefan
Last active August 29, 2015 14:05
Show Gist options
  • Save maier-stefan/6547ed1f4c4ba807c9a9 to your computer and use it in GitHub Desktop.
Save maier-stefan/6547ed1f4c4ba807c9a9 to your computer and use it in GitHub Desktop.
From select tag to link to
<%= form_for :country, :url => {:action =>"change_shipping_country", :controller => "/application"}, :html => {:method => "post"} do |f| %>
<%= select_tag :code2, options_from_collection_for_select(Country.ordered, :code2, :name, @shipping_country.code2), :onchange => "this.form.submit()" %>
<% end %>
<ul>
<%= form_for :country, :url => {:action =>"change_shipping_country", :controller => "/application"}, :html => {:method => "post"} do |f| %>
<li>
<%= submit_tag "#{t :germany}", :name => "germany_button" do %>
<img src="/images/location-de.png">
<% end %>
</li>
<li>
<%= submit_tag "#{t :austria}", :name => "austria_button" do %>
<img src="/images/location-at.png">
<% end %>
</li>
<li>
<%= submit_tag "#{t :switzerland}", :name => "switzerland_button" do %>
<img src="/images/location-ch.png">
<% end %>
</li>
<% end %>
</ul>
and in my Conrtrooller this:
if params[:germany_button]
params[:code2] = "de"
end
...
@fanktom
Copy link

fanktom commented Aug 24, 2014

You're only creating links in a form which doesn't submit any values with the form.

One possible solution is to use multiple submit buttons, and style them as links.

See e.g. here: http://railscasts.com/episodes/38-multibutton-form

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment