【问题标题】:How to update partial using Ajax call and then render in Rails?如何使用 Ajax 调用更新部分然后在 Rails 中渲染?
【发布时间】:2014-07-18 07:02:14
【问题描述】:

我没有使用erb,而是使用haml。就像这样:

$("<%= escape_javascript(render @user) %>").appendTo("#users"); 

http://edgeguides.rubyonrails.org/working_with_javascript_in_rails.html 中不起作用。

有人有想法吗?

【问题讨论】:

    标签: javascript ruby-on-rails ruby ajax haml


    【解决方案1】:

    对于HAML,使用字符串插值如下:

    $("#{escape_javascript(render @user)}").appendTo("#users");  
    

    【讨论】:

    • 我应该把它放在 *.js.haml 文件中吗?我可以在 *.js 文件中使用它吗?
    • *.js.haml 文件,因为它应该由 Ruby 解释。
    猜你喜欢
    • 2013-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-19
    • 1970-01-01
    • 2021-10-16
    • 2013-03-15
    • 1970-01-01
    相关资源
    最近更新 更多