私はこれまでにこの作業をしていましたが、何らかの理由で作成アクションの1つでcurrent_userメソッドを呼び出すとnilが返され続けます。それは他のコントローラなどで使用されたときにうまく動作します(サイドパネルなど)。投稿時の現在のユーザnil
class CombatInstancesController < ApplicationController
def create
# when creating a new instance, check if the current user has one and destroy it
CombatInstance.find(current_user.combat_instance.id).destroy if current_user.combat_instance
# Now create the new one
render :json => current_user.create_combat_instance
end
def update
@combat_instance = current_user.combat_instance
@combat_instance.trigger_actions(params[:actions])
@combat_instance.perform_ai_actions
@combat_instance.save # should we instead call this in an after hook?
render :json => @combat_instance
end
end
CombatInstance.find(current_user.combat_instance.id).destroy if current_user.combat_instance
ラインはCURRENT_USERがnilを返す場合です。ワークフローは次のとおりです。私はホームページに行きます。ログインするだけです。一番上に表示されるユーザー名は、ビューのcurrent_userヘルパーを使用して生成されます。しかし、ここでcreateアクションにヒットするフォームを送信すると、nilが返されます。
私はこれでいいですか?詳細をお知らせください。どの線であなたは無限になっていますか?あなたが経験している正確なエラー/動作は何ですか? –
ログイン後にホームページを更新しても、まだログインしていますか? 'RAILS_DEFAULT_LOGGER.info current_user'(Rails 2)や' Rails.logger.info current_user'(Rails 3)を 'create'アクションの最上部から実行すると、ログにはどうなりますか?あなたは 'CombatInstancesController'や' ApplicationController'に 'before_filters'を持っていますか? –
はい私はまだログインしています。作成アクションの先頭にあるcurrent_userをログファイルに出力すると、空の文字列が出力されます。 – agmcleod