一个模仿 ruby china 的帖子回复功能 前台 form 是这样的:
<%= simple_form_for Reply.new, remote: true, url: topic_replies_path(@topic), html: {class: 'form-horizontal new_reply', id: "new_reply"} do |f| %>
...
<%= f.button :submit, "提交回复", class: 'btn btn-primary', tabindex: "2", data: { disable_with: "正在提交..." } %>
...
<% end %>
后台的代码:
def create
reply = reply_params
reply[:content] = prevent_script(reply_params[:content])
@reply = Reply.new(reply)
@reply.topic_id = @topic.id
@reply.user_id = current_user.id
if @reply.save
@replies_count = @topic.replies_count
flash[:success] = "成功回复!"
respond_to do |format|
format.html { redirect_to topic_path(@topic) }
format.js
end
else
flash[:failure] = "回复失败!"
end
end
从而渲染前台的 create.js.erb 文件,但是在 rails s 或是 rails s -eproduction 命令下,都可以成功添加评论,而在 apache+passenger 服务器上却无法渲染。 出现如下错误:
POST http://XXX.com/topics/1/replies 500 (Internal Server Error) application-889219bf8e8bc14719731fcd3d7ebafb.js:3
XHR finished loading: "http://XXX.com/topics/1/replies".
并且,在将 format.js 改成:
format.js{render js: "alert()"}
能够成功弹出 alert() 窗
比较过用 apache 和 rails s -eproduction 的审查元素: apache 多一个错误就是 POST http://XXX.com/topics/1/replies 500 (Internal Server Error) application-889219bf8e8bc14719731fcd3d7ebafb.js:3
请高手解答。。。