【问题标题】:NoMethodError - undefined method in routes following Railscast 145NoMethodError - Railscast 145 之后路由中的未定义方法
【发布时间】:2011-08-22 18:41:24
【问题描述】:

我正在使用 Rails 3.1 并关注 this railscast 来实现活跃商家,我正在尝试复制剧集中使用的购物车,但出现此错误:

无方法错误

#Rails.root 的未定义方法 `current_cart': /users/dave/work/sell

应用程序跟踪 |框架跟踪 |全跟踪 config/routes.rb:7:in block (2 levels) in <top (required)>' config/routes.rb:6:inblock in ' config/routes.rb:1:in `' 这个错误 加载以下文件时发生:
/users/dave/work/sell/config/routes.rb

我的路线.rb

Sell::Application.routes.draw do

  resources :orders

  current_cart 'cart', :controller => 'carts', :action => 'show', :id => 'current'

  resources :line_items
  resources :carts    
  resources :products 
end

rails cast 版本(通过查看 github 上的源代码)使用 |map| map.resources :无论以何种方式编写 routes.rb。

非常感谢您的帮助!

【问题讨论】:

  • 尝试更改路由,例如get 'cart' => 'carts#show', :as => 'current_cart'
  • @taro,效果很好,非常感谢,添加为答案,我会打勾。

标签: ruby-on-rails routes activemerchant railscasts nomethoderror


【解决方案1】:

尝试改变路线

get 'cart' => 'carts#show', :as => 'current_cart'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-07
    • 2013-04-24
    • 2015-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-01
    • 2019-06-12
    相关资源
    最近更新 更多