【问题标题】:Default path to look for partial查找部分的默认路径
【发布时间】:2014-10-21 04:55:37
【问题描述】:

在我的app/views/conversations/index.html.erb,我正在写:

<%= render @conversations %>

希望它会在同一目录中找到一个名为_conversation.html.erb 的部分,并使用它来渲染@conversations 中的每个元素。 (通常的 Rails 方式)

但我收到一个缺少模板的错误:Missing partial mailboxer/conversations/_conversation

我正在使用Mailboxer gem,并且没有这方面的文档。我知道我可以通过&lt;%= render partial: 'conversation', locals: { conversations: @conversations } %&gt; 显式渲染部分内容。

不过,我仍然想知道为什么我的应用在mailboxer/conversations/ 中寻找@conversations 的部分,而不是conversations/,以及是否有办法改变这种行为。

更多信息

<% @conversations.each do |conversation| %>
  <%= div_for conversation %>
<% end %>

生成 HTML:

<div class="mailboxer_conversation" id="mailboxer_conversation_16"> ... </div>
<div class="mailboxer_conversation" id="mailboxer_conversation_17"> ... </div>
....

或许conversation前面的mailboxer_也与这种情况有关?

【问题讨论】:

  • 这是一个很奇怪的错误。看起来有人在 github 上报告了这个问题 - 我假设是你(如果没有,我会订阅那个线程)。

标签: ruby-on-rails mailboxer


【解决方案1】:

发生这种情况是因为在更高版本的 Mailboxer 中,模型在 Mailboxer 下命名。 (例如 Mailboxer::Conversation、Mailboxer::Message。)

我也在 GitHub 问题上commented

【讨论】:

    【解决方案2】:

    您可以尝试提供部分的完整路径,例如

    <%= render :partial => "yourfoldername/conversation", collection: @conversations %>
    

    【讨论】:

    • Mike 询问原因,为什么他的解决方案没有按预期工作。
    猜你喜欢
    • 2018-08-15
    • 2011-09-21
    • 1970-01-01
    • 1970-01-01
    • 2015-12-21
    • 2023-03-03
    • 2012-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多