Rails how works ApplicationController

1.4k views Asked by At

When i write a Controller Class, it's possible to use methods like:

@article.update(article_params)

The method update comes from the class ActiveRecord::Base : http://api.rubyonrails.org/v2.3/classes/ActiveRecord/Base.html#M001966

My questions:

  1. How can I use the update method from a Controller class that does not inherit from ActiveRecord::Base? It looks like ApplicationController inherits only from ActionController::Base

  2. Are there any resources available to read up on this?

Thanks for help, Cheers B

1

There are 1 answers

2
Josh Bodah On

Rails follow the MVC architecture. In that architecture, your models interact with the database and your controllers interact with incoming requests (usually by orchestrating some models and then passing those off to some views that render the content). Rails achieves reuse through inheritance, so you can't (and probably wouldn't want to) mix concerns

I recommend checking out the official Rails guides. I think it's some of the best written documentation in the industry:

http://guides.rubyonrails.org/