NoMethodError (undefined method `gsub' for #<File:0x007faa7258fd80>) when gsub was never used!

109 views
Skip to first unread message

Myth17

unread,
Mar 5, 2012, 8:23:34 AM3/5/12
to rubyonra...@googlegroups.com
I am presented with this error in my code, the line number happens to be -->

Filestore.create(:filename => uploaded_file.original_filename , :fileblob => uploaded_file.open, :bunch => @current_bunch )

The code directly uses gsub nowehere, what could be the possible issue?

Colin Law

unread,
Mar 5, 2012, 8:43:38 AM3/5/12
to rubyonra...@googlegroups.com
On 5 March 2012 13:23, Myth17 <nitish...@gmail.com> wrote:
> I am presented with this error in my code, the line number happens to be -->
>
> Filestore.create(:filename => uploaded_file.original_filename , :fileblob =>
> uploaded_file.open, :bunch => @current_bunch )

It probably means you are passing a parameter of the wrong type, so
the underlying code is calling gsub, expecting it to be a string I
imagine, but it is actually a File.

What is a Filestore? You should use the techniques described in the
Rails Guide on Debugging to break in and inspect the data to check
that it is what you expect.

Colin

Myth17

unread,
Mar 5, 2012, 10:05:09 AM3/5/12
to rubyonra...@googlegroups.com
FileStore is my model name and I have a table too.

Myth17

unread,
Mar 5, 2012, 1:44:51 PM3/5/12
to rubyonra...@googlegroups.com
I used the puts with 'instance'.class to check the types and they match as well. 


On Monday, March 5, 2012 7:13:38 PM UTC+5:30, Colin Law wrote:

Myth17

unread,
Mar 5, 2012, 2:07:29 PM3/5/12
to rubyonra...@googlegroups.com
I was incorrectly using instance variables which I replaced with session variables. However the problem persists.


On Monday, March 5, 2012 7:13:38 PM UTC+5:30, Colin Law wrote:

Myth17

unread,
Mar 5, 2012, 2:16:33 PM3/5/12
to rubyonra...@googlegroups.com
Replacing open with read solved this issue. Thanks everyone!
Reply all
Reply to author
Forward
0 new messages