1

当我在控制器中执行此操作时:

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_idstrength字段已保存,但我的字段date会自行重置。为什么是这样?

4

0 回答 0