1
新しいプレーヤーを作成するためのコードは次のとおりです。 Player.locationはデータベースではNULLではありませんが、新しいプレーヤー形式で表示したくありません。 Player.location属性を設定するにはどうすればよいですか(ここでは、すべて「UK」に設定されています)Ruby on Rails:コントローラーのフィールドを設定する
# POST /player
# POST /player.xml
def create
@player = Player.new(params[:player])
respond_to do |format|
if @player.save
flash[:notice] = 'Player was successfully created.'
format.html { redirect_to(@player) }
format.xml { render :xml => @player, :status => :created, :location => @player }
else
format.html { render :action => "new" }
format.xml { render :xml => @player.errors, :status => :unprocessable_entity }
end
end
end
あなたは 'before_create'ハンドラ内でこれを置くことをお勧めします。 –