No Route Matches

I'm programming a web system for a rental of movies and put the resource for rent a movie, but the routes don't maches and the rails gives me that message of error. My code and the error gived by rails are in pictures. Thank you for the attention and for the help.

Attachments: http://www.ruby-forum.com/attachment/9100/rails-error-0.png http://www.ruby-forum.com/attachment/9101/rails-error-1.png http://www.ruby-forum.com/attachment/9102/rails-error-2.png http://www.ruby-forum.com/attachment/9103/rails-error-3.png

It is better to copy/paste information rather than linking to images. That way we can insert comments inline in the text. Only post information that is relevant to the problem of course.

Even more significantly you have not posted the contents of routes.rb or shown us the output from rake routes

Colin

Sorry Colin, I'll try to explain in a better way. In my system I have a variable called 'movie' and this 'movie' have a boolean attribute 'rented' that describes if this 'movie' was rented or not. I've created a scaffold to this variable and int this scaffold I put a new link to modify this attribute in this way:

------------------------------------------> index.html.erb (view of the listing)

<h1>Listing movies</h1>

<table>   <thead>     <tr>       <th>Cover</th>       <th>Name</th>       <th>Description</th>       <th>Rented</th>       <th>Genre</th>       <th></th>       <th></th>       <th></th>       <th></th>     </tr>   </thead>

  <tbody>     <% @movies.each do |movie| %>       <tr>         <td><img src="<%= movie.cover %>" width="95"/></td>         <td><%= movie.name %></td>         <td><%= movie.description %></td>         <td><%= movie.rented %></td>         <td><%= movie.genre %></td>         <td><%= link_to 'Rent', action: :rent, :id => movie.id %></td> # the link that I told         <td><%= link_to 'Show', movie %></td>         <td><%= link_to 'Edit', edit_movie_path(movie) %></td>         <td><%= link_to 'Destroy', movie, method: :delete, data: { confirm: 'Are you sure?' } %></td>       </tr>     <% end %>   </tbody> </table>

<br>

<%= link_to 'New Movie', new_movie_path %>

------------------------------------------> movies_controller.rb

class MoviesController < ApplicationController   before_action :set_movie, only: [:show, :edit, :update, :destroy, :rent]

  def index     @movies = Movie.all   end

  def show   end

  def new     @movie = Movie.new   end

  def edit   end

  def create     @movie = Movie.new(movie_params)

    respond_to do |format|       if @movie.save         format.html { redirect_to @movie, notice: 'Movie was successfully created.' }         format.json { render action: 'show', status: :created, location: @movie }       else         format.html { render action: 'new' }         format.json { render json: @movie.errors, status: :unprocessable_entity }       end     end   end

  def update     respond_to do |format|       if @movie.update(movie_params)         format.html { redirect_to @movie, notice: 'Movie was successfully updated.' }         format.json { head :no_content }       else         format.html { render action: 'edit' }         format.json { render json: @movie.errors, status: :unprocessable_entity }       end     end   end

  def destroy     @movie.destroy     respond_to do |format|       format.html { redirect_to movies_url }       format.json { head :no_content }     end   end

  def rent     @movie.to_rent   end

  private     def set_movie       @movie = Movie.find(params[:id])     end

    def movie_params       params.require(:movie).permit(:name, :description, :cover, :rented, :genre)     end end

------------------------------------------> movie.rb

class Movie < ActiveRecord::Base   def to_rent     self.rented = true   end end

------------------------------------------> routes.rb

Locadora::Application.routes.draw do   resources :movies

  # The priority is based upon order of creation: first created -> highest priority.   # See how all your routes lay out with "rake routes".

  # You can have the root of your site routed with "root"   # root 'welcome#index'

  # Example of regular route:   # get 'products/:id' => 'catalog#view'

  # Example of named route that can be invoked with purchase_url(id: product.id)   # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase

  # Example resource route (maps HTTP verbs to controller actions automatically):   # resources :products

  # Example resource route with options:   # resources :products do   # member do   # get 'short'   # post 'toggle'   # end

Sorry Colin, I'll try to explain in a better way. In my system I have a variable called 'movie' and this 'movie' have a boolean attribute 'rented' that describes if this 'movie' was rented or not. I've created a scaffold to this variable and int this scaffold I put a new link to modify this attribute in this way:

Please remember to quote the previous message and insert your reply at appropriate points.

...         <td><%= link_to 'Rent', action: :rent, :id => movie.id %></td> # the link that I told ...

------------------------------------------> routes.rb

Locadora::Application.routes.draw do   resources :movies

  # The priority is based upon order of creation: first created -> highest priority.   # See how all your routes lay out with "rake routes".

  # You can have the root of your site routed with "root"   # root 'welcome#index'

  # Example of regular route:   # get 'products/:id' => 'catalog#view'

  # Example of named route that can be invoked with purchase_url(id: product.id)   # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase

  # Example resource route (maps HTTP verbs to controller actions automatically):   # resources :products

  # Example resource route with options:   # resources :products do   # member do   # get 'short'   # post 'toggle'   # end   #   # collection do   # get 'sold'   # end   # end

  # Example resource route with sub-resources:   # resources :products do   # resources :comments, :sales   # resource :seller   # end

  # Example resource route with more complex sub-resources:   # resources :products do   # resources :comments   # resources :sales do   # get 'recent', on: :collection   # end   # end

  # Example resource route with concerns:   # concern :toggleable do   # post 'toggle'   # end   # resources :posts, concerns: :toggleable   # resources :photos, concerns: :toggleable

  # Example resource route within a namespace:   # namespace :admin do   # # Directs /admin/products/* to Admin::ProductsController   # # (app/controllers/admin/products_controller.rb)   # resources :products   # end end

------------------------------------------> error in browser

No route matches {:action=>"rent", :id=>1, :controller=>"movies"}

You have asked for action rent on the movies controller but you have not provided a route for that.

I suggest you work right through a good tutorial such as railstutorial.org (which is free to use online) which will show you the basics of rails.

If you have a look at the Rails Guide on Routing then it will show you how to do it, but best to work through the tutorial first.

Colin