快速铁路命名路线问题
在我看来,我指定了一个命名路由,如下所示:
show.html.erb ->
seo_path(:id => "45")
现在在我的路线中我定义如下:
routes.rb ->
map.seo "/pages/:id/:permalink", :controller => "pages", :action => "show"
以下是我收到的错误消息。显然 diff 是 id,尽管我不知道为什么。
更新:
我收到此错误:
seo_url failed to generate from {:controller=>"pages", :id=>"45", :action=>"show"}, expected: {:controller=>"pages", :action=>"show"}, diff: {:id=>"45"}
In my view I specify a named route like this:
show.html.erb ->
seo_path(:id => "45")
Now in my routes I define like so:
routes.rb ->
map.seo "/pages/:id/:permalink", :controller => "pages", :action => "show"
Below is the error message I am getting. Apparently the diff is the id, although I don't know why.
Update:
I am getting this as my error:
seo_url failed to generate from {:controller=>"pages", :id=>"45", :action=>"show"}, expected: {:controller=>"pages", :action=>"show"}, diff: {:id=>"45"}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不使用 to_param 方法?
因此获得像这样的路线
除此之外,Rails 似乎无法识别您的路线。您是否重新启动了网络服务器?尝试仅发送 :permalink 属性以查看效果如何。
Why not using the to_param method?
Thus getting routes like
Besides that, it would seems Rails isn't recognizing your route. Have you restarted your web server? Try sending only a :permalink attribute to see how it goes.
我不完全理解你的问题。
看起来
id
已在您的命名路由和视图中指定。看来您还需要在视图中指定permalink
。您收到错误了吗?I don't fully understand your question.
It looks like
id
is already specified in your named route, and in your view. It looks like you need to also specifypermalink
in your view. Are you getting an error?