如何呈现位于不同命名空间中的 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/