Finnnn
Finnnn

Reputation: 3580

setting up named routes for resouce routes in rails

I have what I think should be a simple task - but it's causing me a real headache.

I've added a resource route to my app using -

resources :cars

I want the user to be able to edit a car by going to

mydomain.com/CARNAME

In the edit action of the controller -

@donor = Donor.find_by_name(params[:car])

This page shows by setting up a named route -

match "/:car" =>"cars#edit", :as => :car

However when I try and submit the form on that page I get an error?

How can I set up the show action to have a named route to correspond with the edit route?

My desired show url would be something like

mydomain.com/CARNAME/savecomplete

Upvotes: 0

Views: 445

Answers (1)

railscard
railscard

Reputation: 1848

In routes.rb

match "/:car" =>"cars#edit", :as => :edit_car
match "/:car/savecomplete" =>"cars#show", :as => :savecomplete

In cars_controller.rb update action

format.html { redirect_to(savecomplete_path(@car) }

Upvotes: 2

Related Questions