开发者

Rails 3 URL Helpers Not Working Correctly?

Sigh - Rails 3 routing still seems to confound me. Here's the route.rb line -

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

Here's the code in the view:

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

and here's what gets rendered

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

but what should be rendered is

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

Suggestions? Also, is there a way to have the standard route:

resources :ghost, :only => [:index, :show, :update] do
  get :index
  get :show
开发者_开发技巧  put :update
end

Use ":pid" instead of ":id" without doing the match like I have above?


I think you need admin_ghost_path(@pid), not admin_ghosts_path(@pid). Since you're calling a URL helper that doesn't have any regular arguments, the parameter that you are passing is being treated as a protocol argument value.

To see what the correct helper names for your routes are, run rake routes from the command prompt.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜