Last active
August 29, 2015 14:05
-
-
Save maier-stefan/6547ed1f4c4ba807c9a9 to your computer and use it in GitHub Desktop.
From select tag to link to
This file contains hidden or 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
<%= 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 | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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