当我在我的控制器中执行此操作时:
def new
@army = Army.new(strength: session[:last_army_strength],
type_id: session[:last_type]),
date: session[:last_date])
end
def create
@army = current_user.armies.new(params[:army])
session[:last_army_strength] = params[:army][:strength]
session[:last_type] = params[:army][:type_id]
session[:last_date] = params[:army][:date]
respond_to do |format|
if @army.save
format.html { redirect_to new_army_path, :notice => "New army added" }
else
format.html { render :new }
end
end
end
end
type_id
和strength
字段已保存,但我的date
字段会自行重置。这是为什么?