新手问题 无法渲染 create.js.erb 文件

tsaikoga · 2013年12月21日 · 最后由 tsaikoga 回复于 2013年12月22日 · 3181 次阅读

一个模仿 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

请高手解答。。。

木有人知道遇到这种现象吗?

...换 unicorn 或者 puma 试试看呗。感觉 apache 很非主流啊?

没有遇到过的路过。。

去查一下 Apache 的 error logs,任何 500 错误都有原因,查一下日志大概就能判断出来。

#4 楼 @lgn21st 十分感谢,果然在 error logs 中有显示错误:主要是因为 create.js.erb 访问 tmp/目录下的文件权限不够,更改权限就行了。

huacnlee 关闭了讨论。 08月29日 11:22
需要 登录 后方可回复, 如果你还没有账号请 注册新账号