I have the following code to create a new Player. Player.location is NOT NULL in the database but I do not want to show it in the new player form. How can I set the Player.location attribute (say they're all set to "UK" for now) in here?
# POST /player
# POST /player.xml
def create
@player = Pl开发者_如何学运维ayer.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
Just add this line after your @player = Player.new(params[:player])
line:
@player.location = 'UK'
精彩评论