我正在使用Devise,注册后,我希望我的用户访问profiles/show.html.erb
我有registrations_controller.rb
并且在那里我有这段代码
def after_sign_up_path_for(resource)
new_user_profile_path(current_user)
end
它会将用户定向profiles/new.html.erb
,但我希望用户转到profiles/show.html.erb
rake routes
显示此路径:
new_user_profile GET /users/:user_id/profile/new(.:format) profiles#new
edit_user_profile GET /users/:user_id/profile/edit(.:format) profiles#edit
GET /users/:user_id/profile(.:format) profiles#show
如何修改此代码块以指向profiles/show.html.erb
?
我没有经验可以通过我自己解决这个问题,任何帮助都会很有意义
这是我的routes.rb
文件
Rails.application.routes.draw do
devise_for :users, :controllers => { registrations: 'registrations' }
resources :users do
resource :profile
end
root 'pages#index'
end
**编辑**
the rake routes output
Prefix Verb URI Pattern Controller#Action
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) registrations#cancel
user_registration POST /users(.:format) registrations#create
new_user_registration GET /users/sign_up(.:format) registrations#new
edit_user_registration GET /users/edit(.:format) registrations#edit
PATCH /users(.:format) registrations#update
PUT /users(.:format) registrations#update
DELETE /users(.:format) registrations#destroy
user_profile POST /users/:user_id/profile(.:format) profiles#create
new_user_profile GET /users/:user_id/profile/new(.:format) profiles#new
edit_user_profile GET /users/:user_id/profile/edit(.:format) profiles#edit
GET /users/:user_id/profile(.:format) profiles#show
PATCH /users/:user_id/profile(.:format) profiles#update
PUT /users/:user_id/profile(.:format) profiles#update
DELETE /users/:user_id/profile(.:format) profiles#destroy
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
GET /%20/users/:user_id/profile(.:format)%20 profiles#show
root GET / pages#index
答案 0 :(得分:1)
在您的控制器中,您需要创建
def show
end
您也可以尝试使用。
替换注册控制器中的代码def after_sign_up_path_for(resource)
show_user_profile_path(current_user)
end
答案 1 :(得分:1)
删除'做'来自资源:用户在routes.rb文件中执行。
def after_sign_up_path_for(resource)
user_path(current_user)
end
rake routes
显示user GET /users/:id(.:format) users#show
答案 2 :(得分:1)
我修好了,检查你的github。
拼写你的资源是错误的
它应该是resources :profile
而不是resource :profile
这就是为什么它没有通过rake routes
命令向您显示配置文件资源的路径。
我在profile_controller.rb文件
profile_path(current_user)
答案 3 :(得分:1)
的routes.rb
get 'profiles/show', to: 'profiles/show', as: :profile
profiles_controller.rb
def show
unless params[:user_id] @user = User.find(current_user.id)
@user = User.find(params[:user_id])
end
然后
def after_sign_up_path_for(resource)
profile_path
end