Quantcast
Channel: Being A Dream Walker » Ruby on Rails
Viewing all articles
Browse latest Browse all 5

Rails Helper Function – file.read not working?

$
0
0

Probably one if the simplest mistake I have ever done. But got stucked
with this for an hour before I would figure out what was wrong.

Rails has got a very nice set of helper functions that would generate
the HTML for you. So to upload a file you would probably write something
like this in your view.

But with this if you will try to extract the file in your controller,

params[:model][:image].read will give an error:


NoMethodError (undefined method `read’ for “<file.jpg>”:String)

So how come the image file became a String? Well, if you have done a
silly mistake like me than you have forgotten to add the “multipart”
value in the form.

So simply add this to your form_for tag and it would work like a charm.



Viewing all articles
Browse latest Browse all 5

Trending Articles