快速铁路命名路线问题

发布于 2024-08-05 08:07:02 字数 532 浏览 10 评论 0原文

在我看来,我指定了一个命名路由,如下所示:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深海少女心 2024-08-12 08:07:02

为什么不使用 to_param 方法?

class YourModel << AR::Base

 def to_param
    "#{id}-#{title.parameterize}"
 end

因此获得像这样的路线

/pages/1-here-is-my-converted-article-title-to-permalink

除此之外,Rails 似乎无法识别您的路线。您是否重新启动了网络服务器?尝试仅发送 :permalink 属性以查看效果如何。

Why not using the to_param method?

class YourModel << AR::Base

 def to_param
    "#{id}-#{title.parameterize}"
 end

Thus getting routes like

/pages/1-here-is-my-converted-article-title-to-permalink

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.

奈何桥上唱咆哮 2024-08-12 08:07:02

我不完全理解你的问题。

看起来 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 specify permalink in your view. Are you getting an error?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文