[英]Routes conflict in Ruby on Rails
我正在使用Devise gem ,我为用户创建了一个show
页面。 我的想法是创建一个像www.website.com/:id
这样的简单路径,我将其配置如下所示:
devise_for :users, path: '', path_names: {sing_in: "login", sing_out:
"signout", sing_up: "signup", edit: "edit"},
:controllers => {:registrations => :registrations }
resources :users, only: [:show]
get '/:id' => 'users#show', as: :profile
我的路线工作正常,但除了show
页面,我有static controller
下的页面,例如about
页面。 我希望能够访问它,如www.website.com/about
,这是我如何定义我的static routes
:
get '/about', to: 'static#about'
现在,如果我想重定向到about page
,我收到一个错误:
ActiveRecord::RecordNotFound in UsersController#show
Couldn't find User with 'id'=about
这是我的users_controller.rb
:
class UsersController < ApplicationController
def show
@user = User.find_by_id(params[:id])
@services = @user.services
end
...
end
我试图搜索类似的错误,但没有找到这样的东西。 有人可以告诉我我做错了什么吗?
谢谢你的帮助和时间。
这里有两件事:
在这种情况下,我怀疑您的单级路由正在定义您的get '/:id'
路由。 因此,该路由正在捕获所有/anything
请求,因为路由器认为anything
都是参数。
只需将您的路线定义移动到任何其他/about
等路线的下方,以便首先匹配它们。
像这样:
get '/about', to: 'static#about'
get '/:id' => 'users#show', as: :profile
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.