在
http://guides.rubyonrails.org/action_controller_overview.html
我读到了
Rails creates an instance of that controller and runs the method with the same name as the action.
所以我不明白, Controller 中的 Action 和公共(public)方法有什么区别。 Controller 中的 Action 和公共(public)方法不一样?
最佳答案
Action 也是一个方法,但是它有一个对应的路由,你可以使用它的路由来点击一个 Action ,但是如果它没有任何关联的路由,你就不能调用方法一个 Action 。
例如在 rails new 中,index、create、show、update、delete 和 edit 是默认操作,因为所有这些方法都有与之关联的路由。但是,如果您在 Controller 中定义了一个由操作调用的方法,但它没有任何关联的路由,那么它是一个方法,而不是一个操作。
关于ruby-on-rails - Rails Controller 中的 Action 和方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21927102/