Tiamon
Tiamon

Reputation: 237

uploading file in ruby on rails

Hi I am using paperclip in my rails application to upload files. I would like to know how to pas the original file path in a 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 %>

Upvotes: 0

Views: 127

Answers (2)

Shatabdi Mohapatra
Shatabdi Mohapatra

Reputation: 467

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

Upvotes: 1

Mehul Gurjar
Mehul Gurjar

Reputation: 284

Please make sure you have added :html => { :multipart => true } in your Form. 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

Upvotes: 0

Related Questions