【问题标题】:Working through Rails3 routes通过 Rails3 路线工作
【发布时间】:2011-12-31 06:24:10
【问题描述】:

我做rake routes时有以下情况

next_post /users/next_post/:index(.:format) {:controller=>"users", :action=>"next_post"}

然后,当我的 ERB 文件中有此代码时:

<%= link_to "next", :next_post %>

我收到以下错误,我就是想不通

没有路由匹配 {:controller=>"users", :action=>"next_post"}

我在这里做错了什么?路线本身是这样的

match '/users/next_post/:index', 
        :controller => "users", 
        :action => 'next_post', 
        :as => :next_post

【问题讨论】:

  • :index 参数是干什么用的?
  • 我正在传递我想要返回的帖子的索引。例如,您在第 4 个帖子上,并且想要继续前进。我会通过 5

标签: ruby-on-rails-3 routing


【解决方案1】:

你应该使用这个

<%= link_to "next", next_post_path(@post.id + 1) %>

【讨论】:

  • 谢谢一百万。我只是不知道如何正确传递索引。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-10-11
  • 2020-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-31
  • 2015-07-10
相关资源
最近更新 更多