On Fri, Feb 25, 2011 at 1:38 AM, Jeff Miller <li...@ruby-forum.com> wrote:
> Hello everyone, > I'm working on a Rails 3 social networking app (following RailsSpace > by Addison Wesley) but the book is old and using Rails 2. Thus far I've > been chugging along converting it along the way, but I'm running into > some trouble with my Avatar model. I'm trying to implement it without > having a table in the database. In accordance to the book, I created the > model manually (instead of with generate) and add an initialize > function. I created the corresponding controller and views, but when I > try to upload my avatar, it errors out telling me that database.avatars > doesn't exist. > > This is because chapter 12 of that book tells you to create your Avatar model like so: class Avatar < ActiveRecord::Base When you inherit from ActiveRecord::Base it checks to see that you have a table in the database that matches Avatar. Back when the book was written I'm sure the rules of having a table were not as strict so the author inherited from ActiveRecord::Base as a short cut for not writing his own error handling (see page 378 section 12.2.3). > I'm pretty sure I've got the controller and model right, but I just need > to tell Rails to NOT look in the database for this model... > > Any ideas? > Yes. As others have suggested correctly you do not need to inherit from ActiveRecord::Base in order to have a class in the models folder. Remove < ActiveRecord::Base from the top of your Avatar class. That will take care of it not looking into the database anymore for an Avatar table. After that you will need to write your own error handling for the areas where you were using AR's build in error handling. You'll see them pretty quick when you run your code. The will most likely show up as Undefined Method errors for "errors.add_to_base" and so on. B. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.