简体   繁体   English

使用成员路由的Rails3路由

[英]Rails3 Routing with Member Routes

I tried following the advice in this Rails3 Routes - Passing parameter to a member route 我尝试遵循此Rails3路线中的建议-将参数传递给成员路线

I have: _health.html (partial) 我有:_health.html(部分)

<%= link_to image_tag("icons/pro_gray.png", :border =>'none'), flag_contact_flags_path(@id), :action => "flag", :id => @id, :remote => true, :class => 'flag' %>

routes.rb routes.rb

  resources :contact_flags do 
    get 'flag/:id', :action => 'flag', :on => :collection
  end

When I do this I get this error: ActionView::Template::Error (undefined method `flag_contact_flags_path' for #<#:0x00000101430358>): 当我这样做时,出现以下错误:ActionView :: Template :: Error(未定义的方法“#_#x:0x00000101430358>的flag_contact_flags_path”):

When I rake routes I show: GET /contact_flags/flag/:id(.:format) {:action=>"flag", :controller=>"contact_flags"} 当我耙路线时,显示:GET /contact_flags/flag/:id(.:format){:action =>“ flag”,:controller =>“ contact_flags”}

Why doesn't think work? 为什么认为不起作用?

I really need to pass the :id parameter.. any ideas? 我真的需要传递:id参数..有什么想法吗?

Thanks 谢谢

Looks like you need to change up the route you're pointing to. 看来您需要更改指向的路线。 Try contact_flags_path(@id) instead of flags_contact_flags(@id). 尝试使用contact_flags_path(@id)而不是flags_contact_flags(@id)。

Any luck? 运气好的话?

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

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