作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
@category}) do %> -6ren">
<%= submit_to_remote(:category, :url => params[:id].blank? ? {:action => 'create'} : {:action => "update", :id => @category}) do %>
<table>
<tr>
<th>Name</th>
</tr>
<tr>
<td><%= text_field(:category, :name, :size => 20) %></td>
<td><%= submit_tag(params[:id].blank? ? "New": "Edit") %></td>
</tr>
</table>
<% end %>
我想使用 Ajax 创建新记录。我得到错误未定义方法submit_to_remote我在布局中声明了原型(prototype)文件。 等待答案.......
最佳答案
首先,您的 submit_to_remote
似乎正在尝试定义 form
- 因此请使用 form_for
或 form_tag
.
其次,Rails 3 中不再存在 submit_to_remote
。您需要 form_tag
的 :remote => true
选项,这将使 UJS (不显眼的 JavaScript)介入并让 AJAX 发生。
参见some docs .
关于javascript - 未定义方法submit_to_remote,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13069256/
我不敢相信没有执行此操作的标准方法,但我正在将内容从文本区域提交到 Rails Controller ,它似乎没有保留换行符(任何形式)。 这是我的 View 代码: f.text_area :key
我是一名优秀的程序员,十分优秀!