Rails file field being interpreted as String?

thurmc

I am trying to provide a form field to be a file input on a rails site. My form is set up like the following

<%= form_tag({:action => 'submit_bulk_adjustment',:id => 'uploadForm', :multipart => true}, {:method => :post}) %>
<%= file_field_tag :file, class: "file-selector"  %> ></td>
<%= submit_tag "Submit" %>

There are a few other forms in the field but probably not relevant. I am trying to use the file from the form field in a method (shown below) and I get the error "undefined method `tempfile' for "0033982687_1406831016_BulkTest.csv":String". What am I doing wrong here? I see almost identical code working on another website.

post = params[:file]

if(post == nil)
    raise NoFilenameEnteredError
end

post_path = post.tempfile.to_path.to_s
Dylan Markow

:multipart => true should be part of the second options hash, not the first one (the first one is just for the URL -- I assume that when you submit this form, you're actually seeing "&multipart=true" in the address bar?). Also, as @Vasseurth mentioned, you need to put your form elements in a block connected to the form:

<%= form_tag({:action => 'submit_bulk_adjustment',:id => 'uploadForm'}, {:multipart => true, :method => :post}) do %>
  <%= file_field_tag :file, class: "file-selector"  %>
  <%= submit_tag "Submit" %>
<% end %>

Also, the default method for form_tag is POST, so there's no need to specify that.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

The string "</script>" in an array is interpreted, is there a workaround?

From Dev

enums are being interpreted as Strings

From Dev

Prevent strings from being interpreted as a file handle

From Dev

javascript string interpreted as object

From Dev

Empty string is interpreted as bool in Constructor

From Dev

Nested conditional operator interpreted as String

From Dev

PHP code is not being interpreted

From Dev

Ruby on Rails : String not being converted into html tag

From Dev

HTML output is being interpreted as plain text instead of being received as html

From Dev

Asset file being loaded automatically in Rails app

From Dev

Value returned by DataBinder.Eval is being interpreted as a variable instead of a string

From Dev

Interpreted string literals in Go

From Dev

awk: Preventing result being interpreted as shell command

From Dev

Hidden field not being passed with dropzone.js in rails app

From Dev

String literal not interpreted as type String

From Dev

Python instead of being interpreted shows compiled behaviour

From Dev

Django REST framework tuple being interpreted as a string?

From Dev

preparedStatement.setString(1,"null"), is being interpreted as null instead of a string (after preparedStatement.addBatch())

From Dev

String is not being directed to Output file (C++)

From Dev

problem with alias being interpreted in command arguments

From Dev

enums are being interpreted as Strings

From Dev

Link tag printing rather than being interpreted

From Dev

PHP code is not being interpreted

From Dev

awk: Preventing result being interpreted as shell command

From Dev

String literal not interpreted as type String

From Dev

Unicode string comparison being interpreted as unequal (Python/Django app)

From Dev

CSV file being returned as a single string

From Dev

String is interpreted as wildcard expression

From Dev

MongoDB options in connection string are being interpreted as the database name

Related Related

  1. 1

    The string "</script>" in an array is interpreted, is there a workaround?

  2. 2

    enums are being interpreted as Strings

  3. 3

    Prevent strings from being interpreted as a file handle

  4. 4

    javascript string interpreted as object

  5. 5

    Empty string is interpreted as bool in Constructor

  6. 6

    Nested conditional operator interpreted as String

  7. 7

    PHP code is not being interpreted

  8. 8

    Ruby on Rails : String not being converted into html tag

  9. 9

    HTML output is being interpreted as plain text instead of being received as html

  10. 10

    Asset file being loaded automatically in Rails app

  11. 11

    Value returned by DataBinder.Eval is being interpreted as a variable instead of a string

  12. 12

    Interpreted string literals in Go

  13. 13

    awk: Preventing result being interpreted as shell command

  14. 14

    Hidden field not being passed with dropzone.js in rails app

  15. 15

    String literal not interpreted as type String

  16. 16

    Python instead of being interpreted shows compiled behaviour

  17. 17

    Django REST framework tuple being interpreted as a string?

  18. 18

    preparedStatement.setString(1,"null"), is being interpreted as null instead of a string (after preparedStatement.addBatch())

  19. 19

    String is not being directed to Output file (C++)

  20. 20

    problem with alias being interpreted in command arguments

  21. 21

    enums are being interpreted as Strings

  22. 22

    Link tag printing rather than being interpreted

  23. 23

    PHP code is not being interpreted

  24. 24

    awk: Preventing result being interpreted as shell command

  25. 25

    String literal not interpreted as type String

  26. 26

    Unicode string comparison being interpreted as unequal (Python/Django app)

  27. 27

    CSV file being returned as a single string

  28. 28

    String is interpreted as wildcard expression

  29. 29

    MongoDB options in connection string are being interpreted as the database name

HotTag

Archive