私はRailsを使い始めましたが、現在私はゲームアプリケーションを構築しています。私のゲームは複数のレベルを含んでいます。私は、ゲームのURLに各レベルの番号が含まれていることを願っています。たとえば:パラメータを使用すると定義されていないメソッド `_path '
routes.rbを::
Rails.application.routes.draw do
devise_for :users
resources :game1
get "/game1" => "game1#index"
get "/game1/play/:level" => "game1#play"
get "/game1/instruction" => "game1#instruction"
get "/pages/*page" => "pages#show"
get "/pages/about" => "pages#about"
root "pages#show", page: "home"
end
コントローラ:
class Game1Controller < ApplicationController
def index
end
def play
@game1 = Game1lv.find(params[:level])
@userid = current_user.id
@usergame1lv = User.where(id: @userid).limit(1).pluck(:game1lv)
if @usergame1lv == [nil]
@usergame1lv = 1
end
@game1l = Game1lv.where(:level => @usergame1lv).limit(1).pluck(:imagelink)
@game1a = Game1lv.where(:level => @usergame1lv).limit(1).pluck(:answer)
@game1link = @game1l[0].to_s
@game1answer = @game1a[0].to_s
@game1answer_user = params["answer"]
if @game1answer_user == @game1answer
redirect_to game1_play_path(@game1), :flash => { :success => "You are right!" }
else
#flash.now[:alert] = 'You are wrong! Lets try again!'
end
end
def instruction
end
end
、私は私がのparamsを使用する必要があることを理解し、これを達成するために
http://localhost:3000/game1/play/1
http://localhost:3000/game1/play/2
は、ここに私のコードです
ビュー:
今私がURLにアクセスしてください。
http://localhost:3000/game1/play/1
Railsがエラーを示しています。
undefined method `game1_play_path' for #<#<Class:0x943de50>:0x9447720>
レールのエラーが表示ファイルに次の行にあることを示しています
<%= form_tag game1_play_path(@game1), :method => :get, :id => "text_form" do %>
私が間違っていること、なぜそのメソッドが定義されていないのかを教えてください。前もって感謝します。
この '取得してみてください「game1_play'' – Pavan
はあなたをとても感謝パヴァン! – Marco