简体   繁体   English

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

[英]Data between Partials and Parent View Ruby on Rails

So I have a new.html.erb which contains the form for a new ad. 因此,我有一个new.html.erb,其中包含新广告的表单。 This view renders a partial to upload images called _upload_control.html.erb. 此视图呈现了部分上传的名为_upload_control.html.erb的图像。 It contains <%= file_field_tag :fileupload %> and I'm trying to reference the uploaded in new.html.erb in order to get the file in the parent's controller. 它包含<%= file_field_tag:fileupload%>,我试图引用new.html.erb中上传的内容,以便在父级的控制器中获取文件。 Is there a way to do this? 有没有办法做到这一点?

As per your comment 根据您的评论

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

You should use f(form builder) and need to pass your form builder in locals so that your partial can be called with that particular form builder, something like: 您应该使用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 %>

and your partial _upload_control.html.erb 和您的部分_upload_control.html.erb

<%= f.file_field :fileupload %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM