ruby-on-rails - rails : Rendering a template in a different namespace

标签 ruby-on-rails namespaces

如何呈现位于不同命名空间中的 Controller 的操作?

例如,如果我在 Webapp 命名空间 Webapp::LoginController 中有一个登录 Controller 并且我想在 API 命名空间 API::EventsController 中的事件 Controller 中呈现索引操作(不是部分操作!)如果用户已登录:

class Webapp::LoginController < ApplicationController
  include Webapp::LoginHelper
  def index
    render 'events/index' if logged_in? # events#index is in the API namespace
   end
end

这甚至可能吗 ?我认为答案是否定的,因为与子域和路径存在潜在冲突,具体取决于路由的定义方式。

我知道我可以重定向 到我想要的页面
redirect_to api_events_url

但这会创建一个我不一定想要的新请求。

最佳答案

这对我有用

render 'api/events/index'

关于ruby-on-rails - rails : Rendering a template in a different namespace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30765406/

相关文章:

c++ - 如何处理 Visual Studio C++ 中的 math.h 污染?

c# - NDepend 中解决方案范围的命名空间依赖关系图

python - 如何将 tensorflow.keras 模型移动到 GPU

C# 多类库具有共同的基类/命名空间问题

xml - XSLT 匹配和命名空间

ruby-on-rails - Rails RESTful 删除嵌套资源

ruby-on-rails - 何时何地实现 ACL

mysql - 如何使用 SQL 或 Sphinx 查找相关标记记录

ruby-on-rails - Rails # 在 HTML href 中注释掉该行

ruby-on-rails - 使用 Shoulda Ruby on Rails 获取 HTTP 响应