没有路线匹配{:action =>“show”,:controller =>“锦标赛”}但是佣金路线显示锦标赛#show

时间:2013-10-19 13:46:20

标签: ruby-on-rails ruby ruby-on-rails-4 rails-routing

错误:没有路线匹配{: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

routes.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

...

我做错了什么? (随着我在这个菜鸟问题上的进展,将会更新)

1 个答案:

答案 0 :(得分:2)

您必须提供您希望展示的锦标赛实例的ID。它就在:id输出中的rake routes处。

如果您执行create操作时发生错误,则可能需要redirect_to tournament_path(@tournament)(或仅redirect_to @tournament)。