[英]Rails3 Routes - Passing parameter to a member route
I would like to pass an extra parameter to a member route of a resource 我想将一个额外的参数传递给资源的成员路由
something like: 就像是:
resources :events do
member do
get 'register/:participant_type_id'
end
end
I could only accomplish it using a static match statement 我只能使用静态匹配语句来完成它
Looking around the internet I saw that this might be possible in Rails 3.0.2. 环顾互联网,我发现在Rails 3.0.2中这可能是可行的。 I'm using 3.0.1 and it certanlly is not. 我使用的是3.0.1而且它不是。
Am I doing something wrong? 难道我做错了什么? or is it really not possible? 还是真的不可能?
thanks 谢谢
Try this: 尝试这个:
resources :events do
member do
get 'register/:participant_type_id', :action => 'register'
end
end
Just to complete the answer with my little findings. 只是用我的小发现完成答案。 It also confused me for quite a while. 它也困扰了我很长一段时间。
In Rails3, the member route with parameters will not have the automatic generated xx_yy_path
helper. 在Rails3中,带参数的成员路由不具有自动生成的xx_yy_path
帮助程序。 You need to add it providing the :as =>
part, omitted the resources
name. 您需要添加它,提供:as =>
部分,省略resources
名称。
Regarding the example provided, to get register_event_path
and register_event_url
, you need to define it like the following: 关于提供的示例,要获取register_event_path
和register_event_url
,您需要像下面这样定义它:
resources :events do
member do
get 'register/:participant_type_id', :action => 'register', :as => 'register'
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.