Reputation: 580
My Task is to submit a form to place_order
action inside Checkout
controller.
This is how I wrote form in my view file i.e
<%= form_for (@order), url: {action: "place_order"} do |f| %>
It does reach inside this method and as I save object i want to redirect
to some other method in the same class. This method name is thank_you
. My code looks like this inside place_order
method
if @order.save
redirect_to :action => 'thank_you'
else
...
end
But it redirects to show method of this class. If I change redirect to other class, it redirects fine but on other action of same controller
, it always redirects to show
.
Here is how I defined my routes
resources :checkout
resources :photos
devise_for :users
resources :carts
post 'checkout/place_order'
match 'checkout/thank_you', to: 'checkout#thank_you', via: [:get]
I need some expert opinion on this. Please help.
Upvotes: 0
Views: 818
Reputation: 2868
Move your thank_you
route above resources :checkout
.
From Rails guides:
Rails routes are matched in the order they are specified, so if you have a resources :photos above a get 'photos/poll' the show action's route for the resources line will be matched before the get line. To fix this, move the get line above the resources line so that it is matched first.
Upvotes: 3