【问题标题】:Ruby on Rails fail when refresh page with ajax使用 ajax 刷新页面时,Ruby on Rails 失败
【发布时间】:2013-05-18 20:08:05
【问题描述】:

干杯!我在我的 Rails 项目中有远程操作,比如:

def foo
  respond_to do |format|
    format.js {}
  end
end

视野中的某处:

= link_to "foo", foo_path, remote: true

在我的 foo.js.erb 文件中:

$('#bar').html("<%= j render(partial: 'bar') %>");

在我的 _bar.html.haml 部分:

hello, i am bar

一切正常且运行良好,但当我刷新此路线上的页面时,它返回 Missing template 错误。有什么问题?

【问题讨论】:

    标签: javascript ruby-on-rails ajax


    【解决方案1】:

    如果您混合使用不同的格式(在本例中为 erbhaml),则需要指定部分格式。

    This question 提供了答案。代替render(partial: 'bar'),使用:

    $('#bar').html("<%= j render(partial: '/path/bar.html.haml') %>");
    

    【讨论】:

    • 就是这样,您可以修复答案中的链接吗?谢谢。
    • 当然,解决什么问题?我不知道你的根路径。
    • [This question] 链接到问题。
    • 抱歉!刚明白你的意思。更新
    猜你喜欢
    • 2013-03-31
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 2015-01-30
    • 1970-01-01
    • 2013-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多