Reputation: 1891
In
http://guides.rubyonrails.org/action_controller_overview.html
I read that
Rails creates an instance of that controller and runs the method with the same name as the action.
so i don't understand, what is difference between actions and public methods in controller. Actions and public methods in controller are not the same?
Upvotes: 5
Views: 2528
Reputation: 700
In other words, if the method is accessible to the public through the browser e.g. (.../index) then it is a "public method" and such methods are called "actions" in rails.
Upvotes: 0
Reputation: 17834
Action is also a method but it has a corresponding route, you can hit an action by using it's route but you can't call method an action if it doesn't have any route associated with it.
e.g. In rails new, index, create, show, update, delete and edit are default actions, because all these methods have routes associated with them. But if you define a method in the controller which is called by an action but it doesn't have any route associated with it then its a method but not an action.
Upvotes: 10
Reputation: 456
In the case of Ruby on Rails, public methods are equivalent to actions.
The term 'public methods' is term in ruby. 'actions' is term for Ruby on Rails.
Upvotes: 1