我知道这是可能的,但我想渲染一个控制器/动作以响应我routes.rb
中的不同动作,我有:
get ':handle' => 'handler#index'
在handler_controller
,我有:
def index
handle=Handle.where('handle=?',params[:handle]).first
if handle.handle_type=='Location'
# call location / show with id from handle
else
render text: "not found"
end
end
我该怎么做?我应该提一下,我不想做重定向。
答案 0 :(得分:0)
也许这会有所帮助:
def action_that_calls_one_from_another_controller
controller_you_want = ControllerYouWant.new
controller_you_want.request = request
controller_you_want.response = response
controller_you_want.action_you_want
end
答案 1 :(得分:0)
您可以使用“内部重定向”方法解决此问题。
内部轨道可以通过再次调用@app
并跟踪重定向循环的中间件来完成。请参阅教程here
也可以通过利用nginx的X-Accel-Redirect
:为引用的资源制作常规路由,但不是常规重定向发出X-Accel-Redirect
标头,对于用户而言,它就像您的页面呈现而没有重定向。