我在实际的IE中遇到了Rails 4.2.1和Ruby 2.1应用程序的几个问题。如果我将某些内容保存到数据库并进行重定向,则值将在数据库中保存两次。
有没有人也有这个?
将Methode保存在控制器中:
if request.post?
@question.attributes = params[:question]
if @question.save
flash.now[:notice] = t("flash.saved")
update_answers params
redirect_after_save @question
end
end
def update_answers params
if !params[:add].nil?
params[:add].each do | id, data |
answer = Answer.new
data[:question_id] = @question.id
answer.update_attributes data
end
end
end
def redirect_after_save q
if params[:action_after_save] == 'back'
flash[:notice] = I18n.t("flash.saved")
redirect_to :controller => :lessons, :action => :edit, :id => q.lesson_id
end
if params[:action_after_save] == 'new'
flash[:notice] = I18n.t("flash.saved")
redirect_to :action => :new, :id => q.lesson_id
end
if params[:action_after_save] == 'test'
flash[:notice] = I18n.t("flash.saved")
redirect_to :action => :test, :id => q.id
end
end