无法获得编辑路线

时间:2017-10-02 16:11:13

标签: ruby-on-rails

我无法正确编辑用户的路线。

以下是_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

2 个答案:

答案 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 routesbundle exec rake routes以查看生成的路由。