title: Rails - Adding a "Delete" button to a Users Timetable
body: <p>Hi I have a rails App where Users can have a timetable with a one to many relationship.</p>
  
  <p>When i add this</p>
  
  <pre><code>&lt;%= link_to "delete", user, method: :delete,
                  data: { confirm: "You sure?" } %&gt;
  </code></pre>
  
  <p>to _user.html it renders a delete link which deletes a user no problem</p>
  
  <p>but when i add this</p>
  
  <pre><code>&lt;%= link_to "delete", timetable, method: :delete,
                      data: { confirm: "You sure?" } %&gt;
  </code></pre>
  
  <p>to _timetable.html.erb it throws an error</p>
  
  <pre><code>ActionController::RoutingError (No route matches [DELETE] "/timetable.4"):
  </code></pre>
  
  <p>My Routes.rb</p>
  
  <pre><code>  get 'password_resets/new'
    get 'password_resets/edit'
    root 'static_pages#home'
    get 'help' =&gt; 'static_pages#help'
    get 'about' =&gt; 'static_pages#about'
    get 'contact' =&gt; 'static_pages#contact'
    get 'timetable' =&gt; 'timetables#new'
    get 'signup' =&gt; 'users#new'
    get 'mobile' =&gt; 'users#mobile'
    get 'login' =&gt; 'sessions#new'
    post 'login' =&gt; 'sessions#create'
    delete 'logout' =&gt; 'sessions#destroy'
  
  
    resources :account_activations, only: [:edit]
    resources :password_resets, only: [:new, :create, :edit, :update]
    resources :timetables
    resources :users
    resources :projects
  </code></pre>
  
  <p>Timetable Controller</p>
  
  <pre><code> class TimetablesController &lt; ApplicationController
  
    before_action :logged_in_user, only: [:create, :destroy]
    before_action :correct_user,   only: :destroy
  
    def index
      @timetables = current_user.timetables.find(current_user)
    end
  
    def new
      @user = User.find(current_user)
      @timetable = Timetable.new
      @timetables = @user.timetables.paginate(page: params[:page], per_page: 1)
    end
  
    def feed
      Timetable.where("user_id = ?", id)
    end
  
    def show
      @feed_items3 = current_user.feed.paginate(page: params[:page])
      @timetable = current_user.timetables.find(params[:id])
    end
  
    def create
      @timetable = Timetable.new(timetable_params)
      @user = User.find(current_user)
  
      if current_user.timetables.create(timetable_params)
        flash[:success] = "Timetable created!"
        redirect_to timetable_path
      else
        flash[:success] = "Timetable not created!"
        redirect_to timetable_path
      end
    end
  
    def destroy
      @timetable = Timetable.find(params[:id])
      @timetable.destroy
      redirect_to timetables_path, notice:  "The timetable #{@timetable.name} has been deleted."
    end
  
    private
    def timetable_params
      params.require(:timetable).permit(:name, :attachment, :id)
    end
  
    def correct_user
      @project = current_user.projects.find_by(id: params[:id])
      redirect_to root_url if @project.nil?
    end
  
  end
  </code></pre>