【发布时间】:2017-02-08 19:41:53
【问题描述】:
我正在尝试使用 ajax 创建一个函数来编辑和更新表单中的 cmets。 我的编辑功能使用 ajax 没有问题,但是当我尝试更新评论时,我收到错误:CommentsController#update 缺少此请求格式和变体的模板。 request.formats: ["text/html"] request.variant: []
cmets_controller
def update
respond_to :js
authorize @comment, :update?
@comment.update(comment_params)
if @comment.save
flash[:notice] = 'Commentaar is succesvol toegevoegd.'
else
flash.now[:alert] = 'Commentaar is niet toegevoegd.'
end
end
def comment_params
params.require(:comment).permit(:text)
end
update.js.erb
$("#comment-ajax-<%= @comment.id %>").html("<%= j render @comment %>");
_comment.html.erb
<% if policy(comment).edit? %>
<%= link_to 'edit', [:edit, comment.fabmoment, comment], remote: true, 'data-type' => 'script' %>
<% end %>
意见表
<%= simple_form_for [fabmoment, comment] do |f| %>
<!-- Input -->
<%= f.input_field :text, rows: 4 %>
<%= f.label :text %>
<% end %>
【问题讨论】:
-
您还可以从视图中显示您的表单代码吗?
-
能否也添加请求参数?
标签: ruby-on-rails ajax