0

Currently I'm using Paperclip to handle my avatar uploads and usage in Rails 3. I have a Users resource (With controller, model, views etc.) where I'm uploading the avatars to (using the users/new view) and they actually upload and work when "embedding" them in the Users show View for example. (I get broken images, but I assume is because of the local server as the images actually save and link to the correct path in my app when looking at the source code) Now, I have another resource called skills (with controller, model and views also) In wich views I need the avatars to show too, but whenever I try to embed/use an user avatar in a skills view I get the following error (The same thing if I try to embed the avatars in another view different from users/show):

undefined methodavatar' for nil:NilClass`

Why is this happening?

Also, as I say, when embeding the avatars in the show view, they actually "embed" but I get broken images and the following Routing error:

No route matches [GET] "/public/assets/users/UserID/thumb/userimage.jpg"

I'm on Localhost... Is because of that? (I'm guessing so because "userimage" it's actually saved on that path in the app)

Could someone explain me what's happening with this routing error and how to use the avatars in multiple views? I'm "embedding" the images with the following code:

<%= image_tag @user.avatar.url(:thumb) %>

Thank You.

Jmlevick
  • 6,504
  • 9
  • 29
  • 35
  • Your `@user` variable is not set properly, fix that issue first. – lee Jun 22 '12 at 03:58
  • Don't understand Humm, I have this in my users controller and Wherever I use @user it works.. O.o: http://pastebin.com/yBMKnWVL – Jmlevick Jun 22 '12 at 04:03
  • @Jmlevick Perhap it is looking under asset directory did you specified `:path` options for `paperclip` – Viren Jun 22 '12 at 04:21
  • @Viren Yep! Look: http://min.us/mbdUu9YKqA Actually the images save in /public/assets/users/UserID/thumb/image-here.jpg – Jmlevick Jun 22 '12 at 04:33

1 Answers1

2

Fixed the problems! For the

undefined methodavatar' for nil:NilClass`

I removed the "@" from user in the following code:

<%= image_tag @user.avatar.url(:thumb) %>

Then, for the following error:

No route matches [GET] "/public/assets/users/UserID/thumb/userimage.jpg"

I had to remove the "public" from my Url Symbol in the user model, so it changed from this:

:url  => "/public/assets/users/:id/:style/:basename.:extension"

To this:

:url  => "/assets/users/:id/:style/:basename.:extension"

Now the images show (in local and production enviroments) and I'm able to use them from all the views I need.

Hope this helps somebody.

Jmlevick
  • 6,504
  • 9
  • 29
  • 35