为什么我的Rails应用程序重定向到`data:,`? [英] Why is my Rails app redirecting to `data:,`?
问题描述
因此,当我在Rails 4应用程序中保存记录时,就会发生这种情况。以下是一些详细信息:
So when I save a record in my Rails 4 app this happens. Here's some details:
- 我正在使用 Ace编辑器。
-
data
属性在我的模型或应用中没有位置。 - 该表单是标准的
form_for
(不是远程)。 - 记录确实已保存
- I'm using the Ace editor.
- The
data
attribute is no where in my model or app. - The form is a standard
form_for
(not remote). - The record does save successfully but then it redirects to this weird ass URL.
更新代码是标准脚手架样板。
The code for the update is standard scaffold boilerplate.
# PATCH/PUT /pages/1
# PATCH/PUT /pages/1.json
def update
respond_to do |format|
if @page.update(page_params)
format.html { redirect_to @page, notice: 'Page was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @page.errors, status: :unprocessable_entity }
end
end
end
有人有什么想法吗?可能有些简单,但我无法一生解决这个问题。让我知道是否还有我可以分享的其他相关信息。
Anyone have any ideas? Probably something simple but I can't for the life of me figure this one out. Let me know if there's any other pertinent information I can share.
推荐答案
在您的特定情况下(快速广播中显示的信息) ,Chrome认为这存在安全隐患,因为您要提交< script>
元素,该元素包含正在使用<插入到页面的可渲染内容中的javascript [Rails内置]异步javascript。
In your specific case (the one shown in your quickcast), Chrome is considering this a security risk because you're submitting a <script>
element containing javascript that's being inserted into the renderable contents of the page using [Rails' built-in] asynchronous javascript.
为避免这种情况,您可以:
To avoid this, you could:
- 剥开包装纸
< script>
标签在提交表单之前使用客户端逻辑,然后在保存记录之前将其重新添加到服务器上。 - 在此控制器中禁用Rails的内置动作更新操作,以便它通过普通的旧HTML提交
- 添加中间重定向页面在表单提交和查看显示操作之间
- Strip out the wrapping
<script>
tags using client-side logic before submitting the form, and then add them back in on the server before saving the record. - Disable Rails' built-in ajaxification of the update action in this controller, so that it submits through plain old HTML
- Add an intermediary redirect page between form submittal and viewing the show action
这篇关于为什么我的Rails应用程序重定向到`data:,`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!