部分和父视图之间的数据Ruby on Rails

时间:2014-06-26 14:00:17

标签: ruby-on-rails model-view-controller partials

所以我有一个new.html.erb,其中包含新广告的表单。此视图呈现部分上载名为_upload_control.html.erb的图像。它包含<%= file_field_tag:fileupload%>我试图引用new.html.erb中上传的文件,以便在父控制器中获取文件。有没有办法做到这一点?

1 个答案:

答案 0 :(得分:0)

根据你的评论

The partial i'm rendering in the form is used to upload multiple files for a different object, so its not using 'f'

您应该使用f(form builder)需要在本地传递表单构建器,以便可以使用该特定表单构建器调用您的部分,例如:

<%= form_for resource1 do |f|  %>
  <%=  render :partial => 'upload_control', :locals => { :f => f }  %>
<% end %>

<%= form_for resource2 do |builder|  %>
  <%=  render :partial => 'upload_control', :locals => { :builder => f }  %>
<% end %>

和您的部分_upload_control.html.erb

<%= f.file_field :fileupload %>