我正在使用设计,在我的显示视图中我有:
<%= link_to "Profile", current_user %>
访问视图时,出现错误:
No route matches {:controller=>"users", :action=>"show"} missing required keys: [:id]
我的表演方法(由一位非常有帮助的 SO 成员建议):
def show
if params[:id]
if current_user
@user = current_user
else
flash[:notice] = "This page is not available"
redirect_to root_path
end
else
@user = current_user
end
end
我的路线:
devise_for :users, :path => '', :path_names => { :sign_in => 'login', :sign_out => 'logout',
:password => 'password', :confirmation => 'verification',
:unlock => 'unblock', :registration => 'signup',
:sign_up => 'new' }
get 'login' => 'users/login'
devise_scope :user do
get 'login', to: 'devise/sessions#new'
get 'users/login', to: 'devise/sessions#new'
get 'logout', to: 'devise/sessions#destroy'
get 'signup', to: 'devise/registrations#new'
get 'password', to: 'devise/passwords#new'
match 'users/secret', to: "devise/passwords#create", via: :post
match 'sessions/user', to: 'devise/sessions#create', via: :post
match 'users/signup', to: 'devise/registrations#create', via: :post
match 'users/signup', to: 'devise/registrations#create', via: :post
end
#resources :users
#resources :users
resources :sessions
# Authenticated Users:
authenticated :user do
root to: "users#show", as: :authenticated_root
end
# Non-Authenticated Users
root to: 'site#index'
get '', to: 'users#show', as: 'user'
get 'edit', to: 'users#edit', as: 'user/edit'
任何想法为什么 current_user 助手返回错误?