使用“ news_path”; ::新闻资源无法使用“没有路由匹配{:action =>“ show”,:controller =>“ admin / news”}缺少必需的键:[:id]” [英] Using "news_path" for a :news resource doesn't work with `No route matches {:action=>"show", :controller=>"admin/news"} missing required keys: [:id]'
问题描述
我正在实现一个管理子域,并用谷歌搜索来找到答案,但是我没有找到另一个实例。
我的路线如下所示子域部分:
constraints:subdomain => 管理员执行
作用域:module => admin做
资源:新闻,:事件
匹配新闻,:to => ‘news#index’,:as => 'news'
root:to => dashboard#index
结束
结束
事件工作正常,但对于为了使新闻起作用,出于某些原因,我需要添加一条特定的路线来匹配它。可能有助于显示部分错误的生成位置(管理员/共享/菜单):
< ul>
< li><%= link_to'Home',root_path,:class => #{current_class?(root_path)}%>< / li>
< li><%=链接到新闻,news_path,:class => #{current_class?(news_path)}%>< / li>
< li><%= link_to'Events',events_path,:class => #{current_class?(events_path)}%>< / li>
< div class = clearboth>< / div>
< / ul>
如果我要删除匹配路线,则会出现错误:
没有路由匹配{:action => show,:controller => admin / news}缺少必需的键:[:id]
我只是不知道为什么,有什么想法吗?
I am implementing an admin subdomain and have googled to try and find the answer to this, however I have not found another instance.
My routes look like this for the subdomain section:
constraints :subdomain => 'admin' do
scope :module => "admin" do
resources :news, :events
match 'news', :to => 'news#index', :as => 'news'
root :to => "dashboard#index"
end
end
Events works fine, but for some reason in order for news to work I need to add a specific route to match it. It may help to show the partial where the error is generated (admin/shared/menu):
<ul>
<li><%= link_to 'Home', root_path, :class => "#{current_class?(root_path)}" %></li>
<li><%= link_to 'News', news_path, :class => "#{current_class?(news_path)}" %></li>
<li><%= link_to 'Events', events_path, :class => "#{current_class?(events_path)}" %></li>
<div class="clearboth"></div>
</ul>
And then the error if I was to remove the match route:
No route matches {:action=>"show", :controller=>"admin/news"} missing required keys: [:id]
I just don't have a clue why, any thoughts?
I found that this is an issue with rails in that the naming convention news should not be used due to plural issues, news -> new so therefore I had to rename everything to articles instead. Oversight on my part, a tad stupid.
这篇关于使用“ news_path”; ::新闻资源无法使用“没有路由匹配{:action =>“ show”,:controller =>“ admin / news”}缺少必需的键:[:id]”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!