railstutorial.org“设置”链接坏了

时间:2014-12-11 13:52:04

标签: ruby-on-rails railstutorial.org

我正在研究Michael Hartl的轨道教程。我的问题是/user/1/edit渲染完美,但使用edit_user_path(current_user)却没有。

我检查了拼写错误,做了一些搜索,found this似乎可能是同一个问题,但答案并没有让我的链接正常工作。现在,我正试图用Michael's来区分我的代码。

如果有任何其他代码可以提供帮助,请告诉我。 感谢您抽出宝贵时间阅读我的问题。

佣金路线的输出:

    $ bundle exec rake routes
                  Prefix Verb   URI Pattern                             Controller#Action
     password_resets_new GET    /password_resets/new(.:format)          password_resets#new
    password_resets_edit GET    /password_resets/edit(.:format)         password_resets#edit
account_activations_edit GET    /account_activations/edit(.:format)     account_activations#edit
                    root GET    /                                       static_pages#home
                    help GET    /help(.:format)                         static_pages#help
                   about GET    /about(.:format)                        static_pages#about
                 contact GET    /contact(.:format)                      static_pages#contact
                  signup GET    /signup(.:format)                       users#new
                   login GET    /login(.:format)                        sessions#new
                         POST   /login(.:format)                        sessions#create
                  logout DELETE /logout(.:format)                       sessions#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
 edit_account_activation GET    /account_activations/:id/edit(.:format) account_activations#edit
         password_resets POST   /password_resets(.:format)              password_resets#create
      new_password_reset GET    /password_resets/new(.:format)          password_resets#new
     edit_password_reset GET    /password_resets/:id/edit(.:format)     password_resets#edit
          password_reset PATCH  /password_resets/:id(.:format)          password_resets#update
                         PUT    /password_resets/:id(.:format)          password_resets#update
              microposts POST   /microposts(.:format)                   microposts#create
               micropost DELETE /microposts/:id(.:format)               microposts#destroy

添加了相关的日志条目。

  

开始获取“/ edit_user_path(current_user)”for 76.186.33.24 at   2014-12-11 13:59:32 +0000

     

ActionController :: RoutingError(没有路由匹配[GET]   “/ edit_user_path(current_user)”):web-console(2.0.0.beta3)   lib / action_dispatch / debug_exceptions.rb:22:in middleware_call'
web-console (2.0.0.beta3) lib/action_dispatch/debug_exceptions.rb:13:in
call'actionpack   (4.2.0.beta2)lib / action_dispatch / middleware / show_exceptions.rb:30:in   call' railties (4.2.0.beta2) lib/rails/rack/logger.rb:38:in call_app'railties(4.2.0.beta2)lib / rails / rack / logger.rb:20:in   block in call' activesupport (4.2.0.beta2) lib/active_support/tagged_logging.rb:68:in阻止标记为'
  activesupport(4.2.0.beta2)lib / active_support / tagged_logging.rb:26:in   tagged' activesupport (4.2.0.beta2) lib/active_support/tagged_logging.rb:68:in标记了'铁路   (4.2.0.beta2)lib / rails / rack / logger.rb:20:in call' actionpack (4.2.0.beta2) lib/action_dispatch/middleware/request_id.rb:21:in call'rack(1.6.0.beta)lib / rack / methodoverride.rb:22:in {{1} } call'activesupport   (4.2.0.beta2)   LIB / active_support /缓存/策略/ local_cache_middleware.rb:28:在   call'
rack (1.6.0.beta) lib/rack/runtime.rb:17:in
调用'actionpack   (4.2.0.beta2)lib / action_dispatch / middleware / static.rb:103:在call' rack (1.6.0.beta) lib/rack/lock.rb:17:in调用'railties   (4.2.0.beta2)lib / rails / engine.rb:514:在call'
rack (1.6.0.beta) lib/rack/sendfile.rb:113:in
呼叫'机架中   (1.6.0.beta)lib / rack / tempfile_reaper.rb:15:in call' railties (4.2.0.beta2) lib/rails/application.rb:161:in _ call' rack(1.6.0.beta)   lib / rack / lint.rb:37:in call' rack (1.6.0.beta) lib/rack/lint.rb:49:in call'rack(1.6.0.beta)   lib / rack / commonlogger.rb:33:in call' rack (1.6.0.beta) lib/rack/showexceptions.rb:24:in call'rack(1.6.0.beta)   lib / rack / content_length.rb:15:in call' rack (1.6.0.beta) lib/rack/chunked.rb:54:in service'
  /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:138:in   call' rack (1.6.0.beta) lib/rack/handler/webrick.rb:89:in运行'
  /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/server.rb:295:in   `start in start_thread'

     

渲染   /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/web-console-2.0.0.beta3/lib/action_dispatch/templates/rescues/_trace.html.erb   (1.6ms)呈现   救援/布局中的/usr/local/rvm/gems/ruby-2.1.1@rails4/gems/web-console-2.0.0.beta3/lib/action_dispatch/templates/rescues/routing_error.html.erb(37.1ms)   76.186.33.24 - - [11 / Dec / 2014:13:59:32 +0000]“GET / 500 HTTP / 1.1”500 1477 0.0647

     

的routes.rb

service'
/usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:94:in
     

_header.html.erb

    Rails.application.routes.draw do
  get 'password_resets/new'

  get 'password_resets/edit'

  get 'account_activations/edit'

  root                'static_pages#home'
  get    'help'    => 'static_pages#help'
  get    'about'   => 'static_pages#about'
  get    'contact' => 'static_pages#contact'
  get    'signup'  => 'users#new'
  get    'login'   => 'sessions#new'
  post   'login'   => 'sessions#create'
  delete 'logout'  => 'sessions#destroy'
  resources :users
  resources :account_activations, only: [:edit]
  resources :password_resets, only: [:new, :create, :edit, :update]
  resources :microposts,          only: [:create, :destroy]  
end

1 个答案:

答案 0 :(得分:2)

此:

<%= link_to "Settings", 'edit_user_path(current_user)' %>

应该成为这个:

<%= link_to "Settings", edit_user_path(current_user) %>

您的日志显示该应用会查找/edit_user_path(current_user),因为您将其作为字符串发送,通常您没有此路径。查看日志的第一行Started GET "/edit_user_path(current_user)"

应为Started GET "/users/1/edit"