RAILS3: link_to ( ...method: post...) and No route matches "/dropup"
I'm migrating from rails2 to rails3 and I came across the following error:
Unknown action
The action 'show' could not be found for SessionLocalesController
that's because I have a link_to with a method: post inside.
My previous research indicates that I should use button instead or add <%= javascript_include_tag :defaults %> line to my code, because rails3 is unobtrusive javascrtipt:
1.Button is not a solution because the same problem is happening elsewhere so making this work as it is will solve it as well.
2.The <%= javascript_include_tag :defaults %> seems to work, but it give this error instead:Routing Error No route matches "/dropup"
I'm stuck now. Thanks in advance for your time.
As asked, here's the code:
<% for locale in (I18n.available_locales) -%>
<%= link_to image_tag("flags/" + locale.to_s + ".png", :title=>locale.to_s) + " " + locale.to_s, session_locale_path(:new_locale => locale.to_s), :method => :post %> <%=link_to t('language'), 'dropup', {:id=>"language_select", :class=>"language_select",:title => t('translate.change')} %>
<ul id="language_menu" style="display:开发者_高级运维none">
<% for locale in (I18n.available_locales) -%>
<li><%= link_to image_tag("flags/" + locale.to_s + ".png", :title=>locale.to_s) + " " + locale.to_s, session_locale_path(:new_locale => locale.to_s), :method => :post %> </li>
I've solved this. That same problem has been solved before here in stackoverflow many times, but only after finding the solution I noticed it. Well, here it is>
http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-in-rails-3/
Get jQuery and add the following to your layouts:
<%= javascript_include_tag :defaults %> <%= csrf_meta_tag %>
More info on the link I supplied.
精彩评论