Reputation: 22238
I have a simple class I want to include in my Rails app, but I want to still be able to access all the Rails niceness, e.g use the gems, helpers, routes etc etc as normal.
How can I do this? Is it the right thing to do?
Upvotes: 0
Views: 652
Reputation: 3043
You didn't quite specify what the class is for. If it's a model, put it in the models folder. Don't forget that a model doesn't have to be backed by a database. If you have a class that represents something and has business logic, it's a model.
# models/report.rb
class Report
def self.attendance_for(course)
Enrollment.find :all, :include => [:sections], :conditions => ["sections.course_id = ?", course.id])
end
....
end
The lib folder is also appropriate, but depending on how you name the file and the class definition, you may still need to require it from environment.rb or elsewhere.
Another approach is to use a plugin or a gem to distribute your code.
Upvotes: 3