0

错误:没有路线匹配 {:action=>"show", :controller=>"tournaments"}

class TournamentsController < ApplicationController
  def new
    @tournament = Tournament.new
  end

  def create
    @tournament = Tournament.new(params[:tournament].permit(:description))
    if @tournament.save
      #flash[:notice] = 'tournament was successfully created.'
      #set up links


      redirect_to :action => 'show'
    else
      render :action => 'new'
    end
  end

  def show
    @tournament = Tournament.first
  end
end

路线.rb:

  resources :tournaments do 
    member do
      get "results"
    end

    resources :opportunities do
      member do
        get 'rate'
      end
    end
  end

执行 rake 路由显示:

...

tournament GET    /tournaments/:id(.:format)       tournaments#show

...

我究竟做错了什么?(将随着我通过这个菜鸟问题的进展而更新)

4

1 回答 1

2

You have to provide an ID, of the tournament instance you wish to show. It's right there as :id in the rake routes output.

If the error is occurring when you execute your create action, you may want to redirect_to tournament_path(@tournament) (or just redirect_to @tournament).

于 2013-10-19T13:48:28.433 回答