【发布时间】:2018-04-13 12:23:28
【问题描述】:
我在公司和其他模型(例如工作、位置、人员)之间有一个联合表
_companies.html.erb
<% if company.companylogo %>
<%= link_to (image_tag(company.companylogo.url(:medium), :class => "fw img-responsive", :alt =>"company logo")), company_path(company) %>
<% else %>
<%= link_to (image_tag("http://via.placeholder.com/405x285", :class => "fw img-responsive", :alt =>"company logo")), company_path(company) %>
<% end %>
<p <%= link_to truncate(company.name, :length => 20), company_path(company), :class => "" %> </p>
在 job/index.html.erb 中,我能够将上述公司的所有内容部分渲染为
<%= render job.companies if job.companies.present? %>
其中显示了母公司徽标和公司名称。
现在我想通过创建另一个部分将公司名称与徽标分开: _seperatename.html.erb
**<p <%= link_to truncate(company.name, :length => 20), company_path(company), :class => "" %> </p>**
我的问题是,在 job/index.html.erb 中,如何渲染 _seperatename.html.erb ?
我试过
它抛出错误 ActionView::Template::/jobs 处的错误 #
的未定义局部变量或方法“公司”但是,如果我将 _seperatename.html.erb 中的 ruby 内容替换为正常文本,它会呈现没有错误
【问题讨论】:
-
有点不清楚你在问什么。但是,我认为你需要
render partial: ...DOCS
标签: ruby-on-rails jointable renderpartial