Inheriting from ActiveRecord::Base with no DB table

Hi.

I need to upload a CSV file in my application and I am trying to do so with a sample I found googling around, which defines a model that inherits from ActiveRecord::Base.

The problem I am having is that whenever an error occurs Rails complains because there is no DB table behind the model, which I don't need since there would be nothing to be stored in it.

I would like to be able to not have the table and also use ActiveRecord::Errors capabilities since I would like to keep the look and feel of the rest of the page when handling errors.

Is there a way of telling Rails that there is no table behind the model? And if that is not possible, is there a way to instantiate an ActiveRecord::Errros object inside the class without inheriting from ActiveRecord::Base and make it work the same way as it usually does?

Thanks.

Pepe

A few minutes googling gave me a plugin: http://agilewebdevelopment.com/plugins/activerecord_base_without_table

You will get all classes along with the validation classes from ActiveRecord in this way. Besides you wont need any corresponding table for this model.

I didnt try it out yet but hope you may find it usable. Let me know if it worked for you. Then we would use it if necessary...

Thank you

Samiron paul

http://www.scrumpad.com

Thanks Samiron,

I appreciate you spending your time to help me out. I spent quite a bit of time googling myself but didn't come across this link. I was hoping ActiveRecord itself would have something built in to it. I took a look at attachment_fu but it was way overkill for what I need. I'll also take a look at paperclip to see if that is also a good fit.

Thanks a lot! :slight_smile: