Ruby on rails 带有参考id的Rails曲别针插值查询

Ruby on rails 带有参考id的Rails曲别针插值查询,ruby-on-rails,paperclip,Ruby On Rails,Paperclip,我试图在回形针插值系统中从另一个表中检索字段。 到目前为止,当我使用像3这样的现有参考号时,它是有效的,但当我尝试使用容器id参考字段时,即使它保存在数据库中,它也不起作用 Rails显示此错误: undefined local variable or method `container_id' for Paperclip::Interpolations:Module 表格 <%= form_for @upload, :remote => true, :authenticity_t

我试图在回形针插值系统中从另一个表中检索字段。 到目前为止,当我使用像
3
这样的现有参考号时,它是有效的,但当我尝试使用
容器id
参考字段时,即使它保存在数据库中,它也不起作用

Rails显示此错误:

undefined local variable or method `container_id' for Paperclip::Interpolations:Module
表格

<%= form_for @upload, :remote => true, :authenticity_token => true do |f| %>
  <p>
    <%= f.label :file %><br />
    <%= f.file_field :file %>
    <%= f.hidden_field :container_id, value: @page.container.id %>
  </p>
  <p><%= f.submit "submit"%></p>
<% end %> 

是否有方法查询另一个表并使用带有曲别针插值的字段?

这是因为容器id不在您使用的方法(插值)的范围内

您可以访问的是attachment.instance

如果@upload是一个模型,我建议您将container_id添加为列,然后您可以这样做:

Paperclip.interpolates('container') do |attachment, style|
  attachment.instance.container.url.to_s
end
我不知道这是否是因为你需要更多的信息,比如涉及的模型和关联。比如容器类


希望能有所帮助

哦,没错,我只是需要attachment.instance.container.url.to_,似乎我完全错过了!谢谢你的帮助。我请你投票给其他人,让他们更容易找到答案。
Paperclip.interpolates('container') do |attachment, style|
  attachment.instance.container.url.to_s
end