ruby-on-rails - Rails Controller 中的 Action 和方法

标签 ruby-on-rails



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/

相关文章:

ruby-on-rails - 当用户选择 "#"井号键时,Twilio Call 断开连接

ruby-on-rails - 加载错误 :bcrypt

ruby-on-rails - Rails NoMethod错误: private method on private method?

ruby-on-rails - 在生产环境中运行 Rails 迁移

sql - 使用连接过滤 - Rails

mysql - 从表单提交中提取日期参数时遇到问题

ruby-on-rails - 在预编译 Assets 上出现此错误:TypeError: couldn't digest ActiveSupport::StringInquirer

ruby-on-rails - rails 中的模式匹配( "where column LIKE ' %foo%")与 Postgres

javascript - 语法错误 : Unexpected token true in html generated by ruby

ruby-on-rails - 在开发过程中从 SQLite3 切换到 Postgresql 以适应 Thinking Sphinx