ruby-on-rails - Rails - 如果用约束包装,redirect_to 找不到路由
问题描述
我有这样的路线被约束包裹。
constraints DomainConstraint.new('admin.example.com') do
get '/admin/:page', to: 'admin#browse', as: :admin_index
end
constraints DomainConstraint.new('client.example.com') do
get '/:page', to: 'client#index', as: :client_index
end
现在,当我想通过以下方式将请求从admin.example.com
控制器重定向到client
控制器时:
def some_page
redirect_to action: :client_index,
end
它说:
No route matches
我相信这是因为我用约束包裹了路线。我如何将管理员重定向到客户端使用constraints
?
解决方案
action
如果您未指定控制器名称,则您的代码无法正常工作的原因是params 在同一控制器上采用了操作名称。
更改您的代码
def some_page
redirect_to action: :client_index,
end
到
def some_page
redirect_to controller: 'client', action: :index
end
更多信息在redirect_to
这里
推荐阅读
- createobjecturl - Uncaught TypeError: window.URL.createObjectUrl is not a function at MediaRecorder.recorder.ondataavailable
- python - Python:列表/数组,删除双字字符串
- excel - 如何在同一行上制作 Excel 公式引用单元格?
- c - Openmp simd(增量向量)
- excel - 数一数。列表中的对
- python-3.x - 隐藏小部件时如何阻止 PyQt5 删除小部件?
- php - 名言正则表达式不起作用
- javascript - 在上传期间调整图像大小(Canvas 和 SimpleImage 库)
- pocketsphinx - ubuntu的声音文件到文本文件语音识别,特别是pocketsphinx的使用
- python - 操作系统模块脚本做的事情但是在终端上抛出错误