加入收藏 | 设为首页 | 会员中心 | 我要投稿 51站长网 (https://www.51zhanzhang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
站内搜索:
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

将root重定向到rails 4中的命名路由

发布时间:2020-12-31 06:56:42 所属栏目:Linux 来源:网络整理
导读:我正在尝试使用routes.rb将我的www.example-app.com根目录重定向到www.example-app.com/app/dashboard.目前我正是这样做的: root to: redirect('/app/dashboard') 但是想使用命名路由来做,例如: get 'app/dashboard' = 'accounts#dashboard',as: :account_

我正在尝试使用routes.rb将我的www.example-app.com根目录重定向到www.example-app.com/app/dashboard.目前我正是这样做的:

root to: redirect('/app/dashboard')

但是想使用命名路由来做,例如:

get 'app/dashboard' => 'accounts#dashboard',as: :account_dashboard

但是当我把它放在路线中时:

root to: redirect(account_dashboard_url)

……当然它不起作用,我怎么能这样做?

解决方法

你不能直接在routes.rb中做到这一点(截至目前为止–Rails 4.2),但有一些方法可以使它工作.最简单的IMO是在应用程序控制器中创建一个方法来进行重定向.
# routes.rb

root to: 'application#redirect_to_account_dashboard'

# application_controller.rb

def redirect_to_account_dashboard
  redirect_to account_dashboard_url
end

(编辑:ASP站长)

【免责声明】本站内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

    相关内容
    未处理完善
      无相关信息
    未处理完善