Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
alicia glenn
3,706 Pointsundefined method
I was trying to fix an issue I was having with paperclip that would cause my image uploads to appear broken
now I'm getting this error, and I have no idea where I've written "avatar_file_name" in the code, so I don't understand why I am getting the undefined method error.
NoMethodError in Devise::RegistrationsController#update
undefined method `avatar_file_name' for #<User:>
7 Answers
Chris McKnight
Courses Plus Student 11,045 PointsDo you have a call to has_attached_file :avatar in your User model? If so, it sounds like the user model is missing theavatar_file_name database column. I would double check your migrations and see if they have been run.
alicia glenn
3,706 Pointshi chris,
yes I have the has_attached_file. I have run rake db:migrate a few times, is there a way I can edit the database?
here is my migration:
class AddAvatarToUsers < ActiveRecord::Migration
def change
add_attachment :users, :avatar
end
Chris McKnight
Courses Plus Student 11,045 PointsYou can edit the database manually but migrations are preferred. What type of database are you using? MySQL, SQLite, etc?
Also, your migration is missing and end. It should read
class AddAvatarToUsers < ActiveRecord::Migration
def change
add_attachment :users, :avatar
end
end
alicia glenn
3,706 PointsI believe that I'm using sqlite3 since that's in my gem file. Is there a way to delete the previous migration I did, and re-migrate it safely? Even though I thought I did the migration right the first time, I followed the lesson and the paperclip documentation, weird.
Also thanks for pointing out the missing end.
Chris McKnight
Courses Plus Student 11,045 PointsIn a production app, you would create another migration with a different name if you committed it to source control. In this case, you could fix the migration file, delete db/development.sqlite, run rake db:create, and rake db:migrate. If you have an application like Base for Mac, you can open the SQLite database in a GUI. I think there are free SQLite GUI applications. If you are comfortable with the command line you can use the sqlite command line program.
alicia glenn
3,706 PointsSorry I don't really understand your last comment, what does "committed it to source control" mean? And are you suggesting that I run another migration with a different name? How would I delete the other one? Can I just delete the migration file?
As per the second part of your comment, are you suggestion that I delete the db file in my app and re-creating it? I have Cyberduck is that a good program for looking at the database? If so, a I would open my database in Cyberduck and delete and add things manually?
sorry for the million questions
Chris McKnight
Courses Plus Student 11,045 PointsSource control, such as cvs, git, mercurial, are programs that track changes to your source control. If you were using version control and collaborating with multiple people, troublesome migrations might hinder your collaborators (unless of course you and your collaborators were using a branching model; try the git basics course if you want more information) First, let's try the simplest solution. Since the migration had a syntax error in it, it may not have run when you ran rake db:migrate and would cause the migration with the syntax error and later migrations to not run. This can be problematic if the migration with the error partially runs because on the next rake db:migrate the parts that already ran will cause an exception. In this case you either have to manually rollback and use rake db:rollback to undo the last migration. You could also rollback you entire database to be an empty database by running rake db:migrate VERSION=0. However, this won't work if there are any irreversible migrations.
Cyberduck won't be able to view the database. I am suggesting as a last resort to delete the database and recreate it. I use Base on Mac. Which operating system are you using?
Also, do you have any data in your database or care about your data in the database?
alicia glenn
3,706 PointsAfter a few days of tinkering, I was finally able to get it working, thanks for helping me out chris.