简体   繁体   English

rails包含具有多个参数的路线

[英]rails rest routes with multiple params

I use Refinery CMS blog module to create a simple blog, now I try to customize archive section, I want to add one more param for archive link, default route for archive looks like: 我使用Refinery CMS博客模块创建一个简单的博客,现在尝试自定义存档部分,我想为存档链接添加一个参数,存档的默认路由如下所示:

blog_archive_posts GET     /blog/archive/:year(/:month)(.:format)

now my question is how can I call this in rails and how can I provide the params for blog_archive_posts_path ? 现在我的问题是如何在rails中调用此函数,以及如何为blog_archive_posts_path提供参数?

Try 尝试

<%= link_to "archive for #{year}/#{month}", 
            blog_archive_posts_path(year: @year, month: @month) %>

where @year and @month are defined in your controller appropriately 在控制器中适当定义了@year@month地方

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM