私はDeviseを使用しており、ショービューには次のものがあります:
<%= link_to "Profile", current_user %>
ビューにアクセスすると、次のエラーが表示されます。
No route matches {:controller=>"users", :action=>"show"} missing required keys: [:id]
私の show メソッド (非常に役立つ 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 ヘルパーがエラーを返す理由はありますか?