RubyonRails_newbie
2009-Oct-31 12:47 UTC
*** PLEASE HELP!! *** NoMethodError in AvatarController#upload
Hi Everyone! I''m trying to add the avatar upload functionality in Ruby on rails following the railsspace book. Before I got the code and re-wrote it for my own needs, I wanted to make sure everything worked anyway, so I added the code from the book to the avatar controller etc.. When I attempted an upload, I got an error: NoMethodError in AvatarController#upload So, when I look at the upload function, all seems OK to me. I''m running rails 2.3.3 and have managed to get past every issue so far without reverting back to an earlier version. def upload @title = "Upload Your Avatar" @user = User.find(session[:user_id]) if param_posted?(:avatar) image = params[:avatar][:image] @avatar = Avatar.new(@user, image) if @avatar.save flash[:notice] = "Your avatar has been uploaded." redirect_to hub_url end end end Originally it had a problem because of this: def index # redirect_to hub_url end The error with this code in place reads: undefined local variable or method `hub_url. This is displayed upon accessing url : http://localhost:3000/avatar Can anyone help? I might look for another tutorial to upload avatars, but was hoping there would be a simple solution.. Cheers!
Frederick Cheung
2009-Oct-31 13:06 UTC
Re: *** PLEASE HELP!! *** NoMethodError in AvatarController#upload
On Oct 31, 12:47 pm, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > def index > # redirect_to hub_url > end > > The error with this code in place reads: undefined local variable or > method `hub_url. This is displayed upon accessing url :http://localhost:3000/avatar > > Can anyone help?Nothing to do with your upload function itself - the hub_url method gets created when you declared a named_route called hub in your routes.rb - your book probably describes that in more detail if you need it Fred> > I might look for another tutorial to upload avatars, but was hoping > there would be a simple solution.. > > Cheers!
RubyonRails_newbie
2009-Oct-31 13:59 UTC
Re: *** PLEASE HELP!! *** NoMethodError in AvatarController#upload
There''s nothing in the routes.rb file for this section, so am assuming it hasnt been affected by that, On 31 Oct, 13:06, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Oct 31, 12:47 pm, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > wrote: > > > > > def index > > # redirect_to hub_url > > end > > > The error with this code in place reads: undefined local variable or > > method `hub_url. This is displayed upon accessing url :http://localhost:3000/avatar > > > Can anyone help? > > Nothing to do with your upload function itself - the hub_url method > gets created when you declared a named_route called hub in your > routes.rb - your book probably describes that in more detail if you > need it > > Fred > > > > > > > I might look for another tutorial to upload avatars, but was hoping > > there would be a simple solution.. > > > Cheers!
RubyonRails_newbie
2009-Oct-31 17:01 UTC
Re: *** PLEASE HELP!! *** NoMethodError in AvatarController#upload
Any ideas why this issue is appearing then?? NoMethodError in AvatarController#upload You have a nil object when you didn''t expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.delete On 31 Oct, 13:59, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> There''s nothing in the routes.rb file for this section, so am assuming > it hasnt been affected by that, > > On 31 Oct, 13:06, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On Oct 31, 12:47 pm, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > > wrote: > > > > def index > > > # redirect_to hub_url > > > end > > > > The error with this code in place reads: undefined local variable or > > > method `hub_url. This is displayed upon accessing url :http://localhost:3000/avatar > > > > Can anyone help? > > > Nothing to do with your upload function itself - the hub_url method > > gets created when you declared a named_route called hub in your > > routes.rb - your book probably describes that in more detail if you > > need it > > > Fred > > > > I might look for another tutorial to upload avatars, but was hoping > > > there would be a simple solution.. > > > > Cheers!
Eric
2009-Oct-31 17:04 UTC
Re: *** PLEASE HELP!! *** NoMethodError in AvatarController#upload
Fred''s right. If hub_url is news to you, it''s probably either a bug in the book or a skipped section by you. -eric On Oct 31, 6:59 am, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> There''s nothing in the routes.rb file for this section, so am assuming > it hasnt been affected by that, > > On 31 Oct, 13:06, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Oct 31, 12:47 pm, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > > wrote: > > > > def index > > > # redirect_to hub_url > > > end > > > > The error with this code in place reads: undefined local variable or > > > method `hub_url. This is displayed upon accessing url :http://localhost:3000/avatar > > > > Can anyone help? > > > Nothing to do with your upload function itself - the hub_url method > > gets created when you declared a named_route called hub in your > > routes.rb - your book probably describes that in more detail if you > > need it > > > Fred > > > > I might look for another tutorial to upload avatars, but was hoping > > > there would be a simple solution.. > > > > Cheers!
RubyonRails_newbie
2009-Oct-31 17:10 UTC
Re: *** PLEASE HELP!! *** NoMethodError in AvatarController#upload
hub_url isn''t causing an issue at the moment, it''s this: NoMethodError in AvatarController#upload You have a nil object when you didn''t expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.delete On 31 Oct, 17:04, Eric <ericgh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Fred''s right. If hub_url is news to you, it''s probably either a bug in > the book or a skipped section by you. > > -eric > > On Oct 31, 6:59 am, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > wrote: > > > > > There''s nothing in the routes.rb file for this section, so am assuming > > it hasnt been affected by that, > > > On 31 Oct, 13:06, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On Oct 31, 12:47 pm, RubyonRails_newbie <craigwest...-gM/Ye1E23myhRSP0FMvGiw@public.gmane.orgm> > > > wrote: > > > > > def index > > > > # redirect_to hub_url > > > > end > > > > > The error with this code in place reads: undefined local variable or > > > > method `hub_url. This is displayed upon accessing url :http://localhost:3000/avatar > > > > > Can anyone help? > > > > Nothing to do with your upload function itself - the hub_url method > > > gets created when you declared a named_route called hub in your > > > routes.rb - your book probably describes that in more detail if you > > > need it > > > > Fred > > > > > I might look for another tutorial to upload avatars, but was hoping > > > > there would be a simple solution.. > > > > > Cheers!
Eric
2009-Oct-31 18:24 UTC
Re: *** PLEASE HELP!! *** NoMethodError in AvatarController#upload
You probably could have included that error in your post. I don''t see .delete in your method, so I''m guessing it''s somewhere deeper. Typically, error messages have line number, so that''s something to check. On Oct 31, 10:10 am, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> hub_url isn''t causing an issue at the moment, > > it''s this: > > NoMethodError in AvatarController#upload > You have a nil object when you didn''t expect it! > You might have expected an instance of ActiveRecord::Base. > The error occurred while evaluating nil.delete > > On 31 Oct, 17:04, Eric <ericgh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Fred''s right. If hub_url is news to you, it''s probably either a bug in > > the book or a skipped section by you. > > > -eric > > > On Oct 31, 6:59 am, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > > wrote: > > > > There''s nothing in the routes.rb file for this section, so am assuming > > > it hasnt been affected by that, > > > > On 31 Oct, 13:06, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On Oct 31, 12:47 pm, RubyonRails_newbie <craigwest...@googlemail.com> > > > > wrote: > > > > > > def index > > > > > # redirect_to hub_url > > > > > end > > > > > > The error with this code in place reads: undefined local variable or > > > > > method `hub_url. This is displayed upon accessing url :http://localhost:3000/avatar > > > > > > Can anyone help? > > > > > Nothing to do with your upload function itself - the hub_url method > > > > gets created when you declared a named_route called hub in your > > > > routes.rb - your book probably describes that in more detail if you > > > > need it > > > > > Fred > > > > > > I might look for another tutorial to upload avatars, but was hoping > > > > > there would be a simple solution.. > > > > > > Cheers!
Joe Grossberg
2009-Nov-01 14:37 UTC
Re: *** PLEASE HELP!! *** NoMethodError in AvatarController#upload
On Oct 31, 8:47 am, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Hi Everyone! > > I''m trying to add the avatar upload functionality in Ruby on rails > following the railsspace book. >Check the book''s website for errata: http://railsspace.com/book/errata There is also a Google Group dedicated to the book: http://groups.google.com/group/railsspace?hl=en Lastly -- believe it or not -- your subject line ("*** PLEASE HELP!! ***") actually makes people less likely to help.
Matt Jones
2009-Nov-01 15:30 UTC
Re: *** PLEASE HELP!! *** NoMethodError in AvatarController#upload
A couple things: - Railsspace isn''t the best tutorial to start with - the ideas are good, but trying to update a 1.2.3-era tutorial to present isn''t the most helpful. It also re-implements a lot of things that have mostly been rolled into popular plugins (authentication for one; also this whole image upload bit). - In general, always post as much backtrace from an error as you can. The final error is sometimes really just where the code fell down after wandering in the woods for a while. - Similarly, if you''re troubleshooting a controller action, posting the log output for the action is handy as well; I''ve chased more than one bug in my own code that came down to a missing method= on a form, which shows up immediately in the log. - You are almost certainly missing something from the earlier chapters of Railsspace - I found the relevant discussion of routing (re: hub_url) in Chapter 9, Listing 9.39. Hope this helps! --Matt Jones On Oct 31, 7:47 am, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Hi Everyone! > > I''m trying to add the avatar upload functionality in Ruby on rails > following the railsspace book. > > Before I got the code and re-wrote it for my own needs, I wanted to > make sure everything worked anyway, so I added the code from the book > to the avatar controller etc.. > > When I attempted an upload, I got an error: NoMethodError in > AvatarController#upload > > So, when I look at the upload function, all seems OK to me. I''m > running rails 2.3.3 and have managed to get past every issue so far > without reverting back to an earlier version. > > def upload > @title = "Upload Your Avatar" > @user = User.find(session[:user_id]) > if param_posted?(:avatar) > image = params[:avatar][:image] > @avatar = Avatar.new(@user, image) > if @avatar.save > flash[:notice] = "Your avatar has been uploaded." > redirect_to hub_url > end > end > end > > Originally it had a problem because of this: > > def index > # redirect_to hub_url > end > > The error with this code in place reads: undefined local variable or > method `hub_url. This is displayed upon accessing url :http://localhost:3000/avatar > > Can anyone help? > > I might look for another tutorial to upload avatars, but was hoping > there would be a simple solution.. > > Cheers!
AGoofin
2009-Nov-01 19:19 UTC
Re: *** PLEASE HELP!! *** NoMethodError in AvatarController#upload
No need to reinvent the wheel with file uploads, I''ve used PaperClip to handle uploaded images and files with little trouble. It''s very easy to configure as to where the information gets stored - in the database or out. On Oct 31, 8:47 am, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Hi Everyone! > > I''m trying to add the avatar upload functionality in Ruby on rails > following the railsspace book. > > Before I got the code and re-wrote it for my own needs, I wanted to > make sure everything worked anyway, so I added the code from the book > to the avatar controller etc.. > > When I attempted an upload, I got an error: NoMethodError in > AvatarController#upload > > So, when I look at the upload function, all seems OK to me. I''m > running rails 2.3.3 and have managed to get past every issue so far > without reverting back to an earlier version. > > def upload > @title = "Upload Your Avatar" > @user = User.find(session[:user_id]) > if param_posted?(:avatar) > image = params[:avatar][:image] > @avatar = Avatar.new(@user, image) > if @avatar.save > flash[:notice] = "Your avatar has been uploaded." > redirect_to hub_url > end > end > end > > Originally it had a problem because of this: > > def index > # redirect_to hub_url > end > > The error with this code in place reads: undefined local variable or > method `hub_url. This is displayed upon accessing url :http://localhost:3000/avatar > > Can anyone help? > > I might look for another tutorial to upload avatars, but was hoping > there would be a simple solution.. > > Cheers!
RubyonRails_newbie
2009-Nov-01 19:57 UTC
Re: *** PLEASE HELP!! *** NoMethodError in AvatarController#upload
cool - thanks for the advice... I''ll check out paper clip... Is it easy to figure out? On 1 Nov, 19:19, AGoofin <amor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> No need to reinvent the wheel with file uploads, I''ve used PaperClip > to handle uploaded images and files with little trouble. > > It''s very easy to configure as to where the information gets stored - > in the database or out. > > On Oct 31, 8:47 am, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > wrote: > > > > > Hi Everyone! > > > I''m trying to add the avatar upload functionality in Ruby on rails > > following the railsspace book. > > > Before I got the code and re-wrote it for my own needs, I wanted to > > make sure everything worked anyway, so I added the code from the book > > to the avatar controller etc.. > > > When I attempted an upload, I got an error: NoMethodError in > > AvatarController#upload > > > So, when I look at the upload function, all seems OK to me. I''m > > running rails 2.3.3 and have managed to get past every issue so far > > without reverting back to an earlier version. > > > def upload > > @title = "Upload Your Avatar" > > @user = User.find(session[:user_id]) > > if param_posted?(:avatar) > > image = params[:avatar][:image] > > @avatar = Avatar.new(@user, image) > > if @avatar.save > > flash[:notice] = "Your avatar has been uploaded." > > redirect_to hub_url > > end > > end > > end > > > Originally it had a problem because of this: > > > def index > > # redirect_to hub_url > > end > > > The error with this code in place reads: undefined local variable or > > method `hub_url. This is displayed upon accessing url :http://localhost:3000/avatar > > > Can anyone help? > > > I might look for another tutorial to upload avatars, but was hoping > > there would be a simple solution.. > > > Cheers!