我无法正确编辑用户的路线。
以下是_header.html.erb
,其中包含编辑用户链接:
<li><%= link_to "Settings", edit_user_path(current_user) %></li>
和routes.rb
:
Rails.application.routes.draw do
root 'static_pages#home'
get 'help' => 'static_pages#help'
get 'about' => 'static_pages#about'
get 'contact' => 'static_pages#contact'
get 'contact' => 'static_pages#contact'
get 'signup' => 'users#new'
get 'login' => 'sessions#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'
get '/all_users', :to => 'users#index'
get '/users/:id', :to => 'users#show', :as => :user
resources :users do
get user
end
resources :account_activations, only: [:edit]
end
修改
我添加了
get 'edit' => 'static_pages#edit'
现在存在同样的问题,但它说有一个UrlGenerationError
。
答案 0 :(得分:0)
删除:
get '/all_users', :to => 'users#index'
get '/users/:id', :to => 'users#show', :as => :user
get user
end
并使用:
resources :users do
resources :account_activations, only: [:edit]
end
哪个会给你:
edit_user_account_activation GET /users/:user_id/account_activations/:id/edit(.:format) account_activations#edit
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
答案 1 :(得分:0)
你只需要制作这样的路线:
> resources :users do
//extra routes goes here if you want to make out of it
end
在rails控制台中运行rake routes
或bundle exec rake routes
以查看生成的路由。