RAILS3: link_to ( ...method: post...) 并且没有路由匹配“/dropup"; [英] RAILS3: link_to ( ...method: post...) and No route matches "/dropup"

查看:38
本文介绍了RAILS3: link_to ( ...method: post...) 并且没有路由匹配“/dropup";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从 rails2 迁移到 rails3,但遇到以下错误:

I'm migrating from rails2 to rails3 and I came across the following error:

未知操作
找不到 SessionLocalesController 的动作show"

Unknown action
The action 'show' could not be found for SessionLocalesController

那是因为我有一个带有方法的 link_to:post inside.

that's because I have a link_to with a method: post inside.

我之前的研究表明我应该使用按钮而不是在我的代码中添加 <%= javascript_include_tag :defaults %> 行,因为 rails3 是不显眼的 javascrtipt:

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 不是解决方案,因为在其他地方也发生了同样的问题,所以按原样进行工作也可以解决它.
2.<%= javascript_include_tag :defaults %> 似乎 可以工作,但它却给出了这个错误:

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:

路由错误没有路由匹配/dropup"

Routing Error No route matches "/dropup"

我现在卡住了.在此先感谢您的时间.

I'm stuck now. Thanks in advance for your time.

如所问,代码如下:

<% 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>  

推荐答案

我已经解决了这个问题.同样的问题在stackoverflow之前已经解决了很多次,但只有在找到解决方案后我才注意到它.嗯,这里是>

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/

获取 jQuery 并将以下内容添加到您的布局中:

Get jQuery and add the following to your layouts:

<%= javascript_include_tag :defaults %><%= csrf_meta_tag %>

<%= javascript_include_tag :defaults %> <%= csrf_meta_tag %>

有关我提供的链接的更多信息.

More info on the link I supplied.

这篇关于RAILS3: link_to ( ...method: post...) 并且没有路由匹配“/dropup";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆