我有一个 Ruby on Rails 和 ActiveAdmin 应用程序。除了添加和注册一些模型外,我基本上没有更改任何默认配置。
我想使用类似 GET/heartbeat
的路由启用我的应用程序,并使用简单的字符串响应客户端/用户。我想知道如何执行以下步骤:
- 将自定义路由添加到我的
routes.rb
文件。 - 在
app/controllers
路径下添加自定义 Controller 。 - 执行自定义操作并在没有任何 View 的情况下直接响应用户。
最佳答案
路线.rb:
get 'heartbeat' => "custom_controller#heartbeat"
自定义 Controller .rb:
class CustomController < ApplicationController
def heartbeat
render inline: "Some string to the client/user"
end
end
关于ruby-on-rails - 如何在 Ruby on Rails 中添加自定义路由、 Controller 和操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33857227/