简体   繁体   English

在Rails上用ruby上传文件

[英]uploading file in ruby on rails

Hi I am using paperclip in my rails application to upload files. 嗨,我在Rails应用程序中使用回形针上传文件。 I would like to know how to pas the original file path in a form_tag. 我想知道如何在form_tag中粘贴原始文件路径。 Or get the original file path in the controller, to be specific Thanks 或获取控制器中的原始文件路径,具体来说谢谢

<%= form_tag upload_categories_path, :method => :get do %>
    <td><%= file_field_tag :file_name %></td>
    <td><%= submit_tag t('submit') %></td>
<% end %>

Modify your form tag : 修改表单标签:

<%= form_tag upload_categories_path, :html => { :multipart => true }, :method => :get do %>
    <td><%= file_field_tag :file_name %></td>
    <td><%= submit_tag t('submit') %></td>
<% end %>

In your post action, you can get the file path by: 在发布操作中,您可以通过以下方式获取文件路径:

params[:file_name].path

Please make sure you have added :html => { :multipart => true } in your Form. 请确保在表单中添加了:html => {:multipart => true}。 like 喜欢

<%= form_tag upload_categories_path, :method => :get, :html => { :multipart => true } do %>
    <td><%= file_field_tag :file_name %></td>
    <td><%= submit_tag t('submit') %></td>
<% end %>

Ref uploading file rails 参考上传文件轨道

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

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