*** 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!

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

There's nothing in the routes.rb file for this section, so am assuming
it hasnt been affected by that,

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

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

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

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.

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.

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

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.

cool - thanks for the advice...

I'll check out paper clip...

Is it easy to figure out?