使用多个参数配置rails3路由
我拥有的
match "/home/markread/:id" => "books#markread"
转到
def markread
#mark params[:id] as read
end
我想要的
如果我想传递另一个参数,使网址看起来像这样,该怎么办 /home/markread/1/didread=read
或 /home/markread/1/didread=unread
所以我的方法将更改为
def marked
#mark params[:id] as params[:didread]
end
问题
什么我的 routes.rb
应该是什么样子才能实现这一目标?
What I have
match "/home/markread/:id" => "books#markread"
goes to
def markread
#mark params[:id] as read
end
What I want
What If I want to pass another parameter so that urls looks like/home/markread/1/didread=read
or /home/markread/1/didread=unread
so my method will change to
def marked
#mark params[:id] as params[:didread]
end
Question
what should my routes.rb
look like for me to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只更改为怎么样
How about just changing to
使用“as”选项为路由命名,并传递任意数量的可选参数。
例如:
这将为您提供诸如
markread_path
和markread_url
之类的帮助器。您可以传递像 markread_path(:id => 1, :other => 'value' ...) 这样的参数您需要在控制器中检查该操作是否有特定参数通过与否。 Rails 文档
Give the route a name using the 'as' option and pass the optional parameters as many you want.
For example:
This will give you helpers like,
markread_path
andmarkread_url
. You can pass theparameters like markread_path(:id => 1, :other => 'value' ...)
You need to do the checks in the controller for that action whether a particular parameter is passed or not. Rails Doc.
在 Rails 4 中,您将拥有:
GET /home/:id/markread/:another(.:format) /home#markread
In rails 4 you will have:
GET /home/:id/markread/:another(.:format) /home#markread