Dennis Zelada
Dennis Zelada

Reputation: 33

Routing Error No route matches [POST] "/movies/9/edit"

Hello I am following a rails tutorial, I am using rails 3.2.3 and I have this error Routing Error

No route matches [POST] "/movies/9/edit"

Here is my haml page:

%h2 Edit Movie

= form_tag edit_movie_path(@movie), :method => :put do

= label :movie, :title, 'Title' = text_field :movie, 'title'

= label :movie, :rating, 'Rating' = select :movie, :rating, ['G','PG','PG-13','R','NC-17']

= label :movie, :release_date, 'Released On' = date_select :movie, :release_date

= submit_tag 'Save Changes'

Here is my controller:

def edit

@movie = Movie.find params[:id]

end

def update

@movie = Movie.find params[:id]
@movie.update_attributes!(params[:movie])
flash[:notice] = "#{@movie.title} was successfully updated."
redirect_to movie_path(@movie)

end

and my routes:

movies GET /movies(.:format) movies#index

       POST   /movies(.:format)          movies#create

new_movie GET /movies/new(.:format) movies#new edit_movie GET /movies/:id/edit(.:format) movies#edit

 movie GET    /movies/:id(.:format)      movies#show

       PUT    /movies/:id(.:format)      movies#update

       DELETE /movies/:id(.:format)      movies#destroy

Thanks for the help

Upvotes: 2

Views: 3133

Answers (2)

Andrei S
Andrei S

Reputation: 6516

Well you are trying to post (put) on the edit action which in your routes file is defined with a get (exactly the way the edit action it's supposed to be)

In a standard way you would want to post to either your create or update path, but if you want to send the form to edit, use method get or change your routes for the edit action to accept put

Upvotes: 0

Mark Paine
Mark Paine

Reputation: 1894

The tutorial may be leading you astray.

It's telling you to have your form PUT to the edit path.

You really want to PUT to the normal movie path. An update is implied by the PUT verb.

Instead of:

= form_tag edit_movie_path(@movie), :method => :put do

Try:

= form_tag movie_path(@movie), :method => :put do

Indeed, you may want to find a different tutorial.

Upvotes: 2

Related Questions