Rails Homeland 的 Ajax 调用时如何实现的啊?

zhzenghui · September 02, 2017 · Last by zhzenghui replied at September 02, 2017 · 1139 hits

我想实现列表项被删除后,刷新页面,也就是 Ajax 返回后,做刷新动作就好. 我做了下面代码的动作,

没找到 coffee 代码,Ajax 的操作不知道怎么做。

我参考了管理界面回复删除操作。

erb

<%= link_to '', admin_reply_path(reply), 'data-confirm' => 'Are you sure?', method: :delete, remote: true, class: "fa fa-trash" %></td>

app

def destroy
  @reply.destroy
end

# 连 render json: { ok: 1 } 都没有,困惑???

在 log 里能看到 Rendering admin/replies/destroy.js.erb Rendered admin/replies/destroy.js.erb (0.8ms) 我自己抄的没有上面对应的 log 输出

我自己照着抄的,就没有反应。肯定我少写了什么。我自己写 coffee,也完全没有用。文件都没有生成。 配置文件又是这样的。

Rails.application.config.assets.precompile += %w(app.js front.css turbolinks-app.css admin.css)

官网文档的实现和 homeland 完全不一样。谁有研究过吗,求帮助,谢谢了。

就是 destory.js.erb 里面有段 JS 实现的

def destroy
  @reply.destroy
  render js: "window.location.reload()"
end
Reply to huacnlee

谢谢,大佬。

Reply to ad583255925

谢谢,我试试。

You need to Sign in before reply, if you don't have an account, please Sign up first.