开发者

Routing problem in Rails 3: ActionController::RoutingError (No route matches ...)

I've created a custom RESTful action called "post". It appears in TransactionsController as a (public) method called post.

resources :transactions do
  member :post do
    post :post
  end
end

I've got a form configured as follows:

<form action="/transactions/25/post">
   ...
   <input id="transac开发者_StackOverflow社区tion_submit" commit="commit" type="submit" value="Post">
</form>

When I hit the "Post" button, my server receives:

POST "/transactions/25/post"

I expect this to call the "post" method in my TransactionController but instead I'm getting a routing error

ActionController::RoutingError (No route matches "/transactions/25/post"):

Any ideas? Thanks.

James


finally found a solution, the problem is that form_for adds the hidden _method field with the value "put", because well the transaction already exists, to circumvent this issue I had to do the following:

<%= form_for @transaction, :url => post_transaction_path(@transaction), :html => { :method => :post } do |form| %>

at least that solved the issue for me, see https://rails.lighthouseapp.com/projects/8994/tickets/4884-routing-error-for-restful-resource-under-namespace for further reference

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜