【问题标题】:Rails3 Routing with Member RoutesRails3 路由与成员路由
【发布时间】:2011-10-12 16:36:46
【问题描述】:

我尝试遵循Rails3 Routes - Passing parameter to a member route中的建议

我有: _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

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

当我这样做时,我得到这个错误: ActionView::Template::Error(# 的未定义方法 `flag_contact_flags_path'):

当我搜索路线时,我会显示: GET /contact_flags/flag/:id(.:format) {:action=>"flag", :controller=>"contact_flags"}

为什么认为不起作用?

我真的需要传递 :id 参数.. 有什么想法吗?

谢谢

【问题讨论】:

    标签: ruby-on-rails routing


    【解决方案1】:

    看来您需要更改指向的路线。尝试使用 contact_flags_path(@id) 而不是 flags_contact_flags(@id)。

    运气好吗?

    【讨论】:

    • 谢谢,但没有运气......如果我这样做了,我的标志动作就会一起消失。然后我得到类似“/contact_flags.057da91cb36d438540f74bfed0764af16d86efe5”的东西,id是正确的,但现在动作不对,即使是原来的路线,它也放了句号而不是斜线......只是不知道为什么?跨度>
    • 抱歉,我的办公室仍在 Rails2 中工作,所以我不了解他们在 Rails3 中获得的所有新路由内容。我建议您查看在线路由文档,看看是否有帮助。
    猜你喜欢
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多