加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3 – link_to(:controller =>“something”)h

发布时间:2020-12-16 19:09:57 所属栏目:百科 来源:网络整理
导读:所有! 也许有人知道为什么这样: def index_link(object,content = t("#{object.to_s.pluralize}.index")) #link_to(content,{:controller=object.to_s.pluralize},:scope="") if can?(:read,p(object)) #this doesn't work too link_to(content,:controlle
所有!
也许有人知道为什么这样:
def index_link(object,content = t("#{object.to_s.pluralize}.index"))
  #link_to(content,{:controller=>object.to_s.pluralize},:scope=>"") if can?(:read,p(object)) #this doesn't work too
  link_to(content,:controller=>"trademarks")
  #link_to(content,trademarks_path) #this do work,but I need to set path from object
end

像这样的例外:

No route matches {:controller=>"devise/trademarks"}

堆:

actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:424:in `raise_routing_error'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:406:in `generate'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:453:in `generate'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:481:in `url_for'
actionpack (3.0.3) lib/action_dispatch/routing/url_for.rb:131:in `url_for'
actionpack (3.0.3) lib/action_view/helpers/url_helper.rb:99:in `url_for'
actionpack (3.0.3) lib/action_view/helpers/url_helper.rb:236:in `link_to'
app/helpers/application_helper.rb:53:in `index_link'
app/views/layouts/application.html.erb:20:in `_app_views_layouts_application_html_erb___741328535__615736668_0'
actionpack (3.0.3) lib/action_view/template.rb:135:in `send'
actionpack (3.0.3) lib/action_view/template.rb:135:in `render'

以及如何使它工作?

解决方法

您必须在路径中添加斜杠.
例如:
<li><%= link_to "Events",:controller => "/events",:action => "index" %></li>

资源:
https://github.com/plataformatec/devise/issues/471#issue/471/comment/395243

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读