と私は、私もそこにcurrentplayersを行い、ネストされた二つのモデル、 Gameround>Railsの「redirect_to」ネストしたルート私のレールのアプリで最新モデル
currentplayer Gameroundがplay.html.erbに表示されています。 currentplayerが作られたとき、私はcurrentplayer#showにユーザーをリダイレクトしたいが、私はリンクをルーティングする方法を理解できないようだ。私は考えることができるすべてを試しました。 thiscurrentGameround/ThiscurrentplayerIjustmade
私のコントローラに
のGet URL:
は、だから私は言うのリンクを必要とする
def createPlayerforUser
@latest_game_round = Gameround.order(created_at: :desc).first
@currentplayer = @latest_game_round.currentplayers.create({
log_id: @current_user.id
});
if @currentplayer.save
redirect_to url_for([@gameround, @currentplayer])
end
end
config.routes
resources :gamerounds do
resources :currentplayers
end
resources :gamesessions
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# Artikkel, Alien liste
resources :expansions do
resources :aliens
end
resources :users
# You can have the root of your site routed with "root"
#root 'gamesessions#play'
root 'gamesessions#new'
#root 'application#show'
#root 'public#index'
get "signup", :to => "users#new"
get "login", :to => "sessions#login"
post "login_attempt", :to => "sessions#login_attempt"
get "logout", :to => "sessions#logout"
get "profile", :to => "sessions#profile"
get "setting", :to => "sessions#setting"
get "play", :to => "gamesessions#play"
get "wait", :to => "gamesessions#wait"
get "aliens", :to => "aliens#index"
端末に '$ rake routes'と入力してください。そこにはルートの名前が表示されます。この場合、 'redirect_to gamearound_currentplayer_path(@gamearound、@currentplayer)'になります。 –
答えに時間をとってくれてありがとう:)しかし、私はそれを試してきましたが、それは何らかの理由で動作しません。私は以下のコメントにエラーメッセージを掲載しました。 – Candielope