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="transaction_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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With