I was just looking around rails and noticed there is an app controller but no app model.
Is there no root model in rails ? if not where do you put a piece of code that needs to be in every model.
Thanks, Alex
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Nothing says your controllers have to subclass
ApplicationControllerbut it generally is the standard because the vast majority of rails applications make use of thelayoutcapabilities (which can vary on each controller), so instead of forcing the rare ones without layouts from turning the layout off (layout nilorlayout false) for each controller, they make an ‘abstract’ one that you can turn controller features on and off easily for your whole application.Now for models, you could create an
ApplicationModelfor all of your models to subclass, but there are two things to think about:ActiveRecord::Baseand uses this to turn STI (single table inheritance) on.ApplicationModelwill be an actual model that is expected to have a table in your database. This can lead to problems down the line.To fix these two problems, you have to set
abstract_classto true for ActiveRecord to properly function.In contrast to an abstract ActionController,
abstract_classmust set to true which means the developer must know they cannot remove this line fromApplicationModel. WithApplicationControlleryou can do pretty much whatever you want to it.