I got this error: NoMethodError in PictureController#new You have a nil object when you didn''t expect it! The error occured while evaluating nil.uploaded_file and the line code is here: @picture.uploaded_file = @params[''picture_file''] -- Posted via http://www.ruby-forum.com/.
Can you show a little more code so we can see what''s causing the error? Are you using file_column? Where did you initialize @picture, etc. Fird Abrar wrote:> > I got this error: > > NoMethodError in PictureController#new > > You have a nil object when you didn''t expect it! > The error occured while evaluating nil.uploaded_file> > and the line code is here: > > @picture.uploaded_file = @params[''picture_file''] >-- View this message in context: http://www.nabble.com/Upload-File-tf2002132.html#a5498282 Sent from the RubyOnRails Users forum at Nabble.com.
class PictureController < ApplicationController def new picture = Picture.new() @picture.uploaded_file = @params[''picture_file''] @picture.save redirect_to :action => ''index'' end end Steve Ross wrote:> Can you show a little more code so we can see what''s causing the error? > Are > you using file_column? Where did you initialize @picture, etc.-- Posted via http://www.ruby-forum.com/.
Hello, You forgot the @ sign in the line where you create a new picture object. Greetings, Joran. Fird Abrar wrote:> class PictureController < ApplicationController > def new > picture = Picture.new() > @picture.uploaded_file = @params[''picture_file''] > @picture.save > redirect_to :action => ''index'' > end > end > > Steve Ross wrote: >> Can you show a little more code so we can see what''s causing the error? >> Are >> you using file_column? Where did you initialize @picture, etc.-- Posted via http://www.ruby-forum.com/.
You left the at-sign off picture when you initialized it. s/b: @picture = Picture.new Fird Abrar wrote:> > class PictureController < ApplicationController > def new > picture = Picture.new() > @picture.uploaded_file = @params[''picture_file''] > @picture.save > redirect_to :action => ''index'' > end > end >-- View this message in context: http://www.nabble.com/Upload-File-tf2002132.html#a5505766 Sent from the RubyOnRails Users forum at Nabble.com.