我正在使用 Rails 4.2.3。我想在模态对话框中提交表单,所以我已经像这样设置了我的表单
<%= form_for @my_object, :remote => true do |f| %>
但是如果用户成功提交表单,我想重新加载调用模式对话框的页面,并显示“已成功保存”的通知。我不知道我需要在我的“format.js”中放入什么来实现这一点。到目前为止,这就是我在控制器中所拥有的……</p>
def create
@my_object = MyObject.new(my_object_params)
@current_user = User.find(session["user_id"])
@my_object.user = @current_user
respond_to do |format|
if @my_object.save
format.html { redirect_to controller: "users", action: "index", notice: 'Saved successfully.' }
format.js { render action: ‘../users/index’, notice: ‘Saved Successfully’, location: @my_object }
else
format.html { render action: "index" }
format.js { render json: @my_object.errors, status: :unprocessable_entity }
end
end
end
现在,当我尝试执行上述操作时,成功提交会导致 500 错误,抱怨缺少部分。很确定我有什么是错的。