Rails locals没有在partial中定义

时间:2022-10-08 17:15:20

I am sure I am missing something obvious, but I cannot figure it out.

我确信我错过了一些明显的东西,但我无法弄清楚。

I have one partial that I am using in both the index and show views. The partial behaves as expected when called from the index, but throws a undefined variable or method exception when called from the show.

我有一个部分,我在索引和显示视图中使用。从索引调用时,部分行为与预期一致,但在从sh​​ow中调用时会抛出未定义的变量或方法异常。

Here is my error:

这是我的错误:

undefined local variable or method `jid' for #<#<Class:0x007fe583bb03a8>:0x007fe586a98580>

Here is the render call from the Show view (this one fails)

这是Show视图中的渲染调用(这个失败)

render :partial => 'outcome_chart', :locals => {:jid => @journal.id, :code => @journal.code }

Here is the render call from the Index view (this one works)

这是来自索引视图的渲染调用(这个工作)

render :partial => 'outcome_chart', :locals => {:jid => j.id, :code => j.code }

Here is my partial, I am using HAML syntax

这是我的部分,我正在使用HAML语法

.col-md-12{:id => "journal_chart_#{jid}", :style => 'height: 200px'}
   Chart will load shortly

- series_labels = []
- recommendations_order.each {|r| series_labels.push({label: r }) }
:javascript
  make_journal_outcome_chart("#{jid}", "#{code}", "#{recommendations_order.join(',')}");

Thanks in advance!

提前致谢!

1 个解决方案

#1


1  

may be you are calling it from any other form and the locals needs to be passed from there as well – rubyist Oct 24 at 19:14

可能是你从任何其他形式调用它,当地人也需要从那里传递 - ruby​​ist 10月24日19:14

Found where there was a second call that I had overlooked. Thanks.

找到了我忽略的第二个电话。谢谢。

#1


1  

may be you are calling it from any other form and the locals needs to be passed from there as well – rubyist Oct 24 at 19:14

可能是你从任何其他形式调用它,当地人也需要从那里传递 - ruby​​ist 10月24日19:14

Found where there was a second call that I had overlooked. Thanks.

找到了我忽略的第二个电话。谢谢。