我使用 iframe 在 rails 3.2 中上传文件,在使用 iframe 提交表单后如何在“ajax”调用中重定向我的页面
if @user.save
format.html { redirect_to users_path }
format.json { render json: @user, status: :created, location: @user }
format.js { render :layout => false }
end
我尝试使用,
format.html { render js: "window.location.pathname = #{users_path.to_json}" }
最佳答案
这对我有用:
format.js {render js: "window.location = '#{users_path}';"}
不要忘记引用 '
js 字符串中的 url,因为在您粘贴到问题中的代码中,您似乎忘记了它们
同时使用 users_path
而不是 users_path.to_json
关于ruby-on-rails - rails 3 : How to “redirect_to” in Ajax call when form submited using html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27742701/