简体   繁体   中英

Action and method in Rails controller

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?

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.

eg 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.

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.

换句话说,如果公众可以通过浏览器访问该方法,例如(... / index),那么它就是“公共方法”,这种方法在rails中称为“动作”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM