Rails 被卡在这里了,undefined method `<<'

li_hai_001 · 2012年04月19日 · 最后由 jiffies 回复于 2012年04月21日 · 2890 次阅读

在看 敏捷开发的时候,在第八章的地方,存储 session 到 sqlite 的时候,出现问题 不能将选择的书,放到购物车里面。 出现的错误是: NoMethodError in StoreController#add_to_cart undefined method `<<'

def add_product (product) @items << product end 就是这里出的错误。不知道怎么搞的。
我的系统配置 Ruby version 1.9.3 (i686-linux) RubyGems version 1.8.22 Rack version 1.4 Rails version 3.2.3 JavaScript Runtime therubyracer (V8) Active Record version 3.2.3 Action Pack version 3.2.3 Active Resource version 3.2.3 Action Mailer version 3.2.3 Active Support version 3.2.3 Middleware

ActionDispatch::Static Rack::Lock #ActiveSupport::Cache::Strategy::LocalCache::Middleware:0xa3c5dd4 Rack::Runtime Rack::MethodOverride ActionDispatch::RequestId Rails::Rack::Logger ActionDispatch::ShowExceptions ActionDispatch::DebugExceptions ActionDispatch::RemoteIp ActionDispatch::Reloader ActionDispatch::Callbacks ActiveRecord::ConnectionAdapters::ConnectionManagement ActiveRecord::QueryCache ActionDispatch::Cookies ActiveRecord::SessionStore ActionDispatch::Flash ActionDispatch::ParamsParser ActionDispatch::Head Rack::ConditionalGet Rack::ETag ActionDispatch::BestStandardsSupport

Application root /root/ROR/depot Environment development Database adapter sqlite3 Database schema version 20120419051012

试试

@items = []
@items << product


至于为什么,开动脑筋!!

楼主阴险的没有把 nil.class 帖出来,被 1 楼发现了

呵呵。。

我觉的楼主问得是不是关系问题。如果一楼那样好像没有意义啊。是不是不是@items,item belongs to 某个类,add_product 在这个类里定义的方法,可以 XXX.items << product

需要 登录 后方可回复, 如果你还没有账号请 注册新账号