Rails 3 URL帮助程序无法正常工作?

时间:2011-04-10 23:24:39

标签: ruby-on-rails routing

Sigh - Rails 3路由似乎仍然让我感到困惑。这是route.rb行 -

match "/ghosts/:pid" => 'ghosts#update', :constraints => { :method => 'PUT' }

以下是视图中的代码:

<%= form_tag (admin_ghosts_path(@pid), :method => :put) do |f| %>

这里是渲染的内容

<form accept-charset="UTF-8" action="/admin/ghosts.jbdlljhhxz" method="post">

但应该呈现的是

<form accept-charset="UTF-8" action="/admin/ghosts/jbdlljhhxz" method="post">

连连呢?此外,有没有办法让标准路线:

resources :ghost, :only => [:index, :show, :update] do
  get :index
  get :show
  put :update
end

使用“:pid”代替“:id”而不像上面那样进行匹配?

1 个答案:

答案 0 :(得分:1)

我认为您需要admin_ghost_path(@pid),而不是admin_ghosts_path(@pid)。由于您正在调用没有任何常规参数的URL帮助程序,因此您传递的参数将被视为协议参数值。

要查看路由的正确帮助程序名称,请从命令提示符运行rake routes

相关问题