2011-06-04 37 views
0

我想學習使用敏捷Web開發和Rails第三版的Ruby on Rails,並且我完全被卡住了。我在Linux Mint上使用Ruby 1.8.7和rails 2.3.5。在本書建議我從cookie更改爲SQLite數據庫來管理會話之後,該應用程序不再有效。我得到的,當我點擊「加入購物車」按鈕,在http://localhost:3000/store以下錯誤:StoreController中的LoadError#add_to_cart

LoadError預期/home/dave/work/depot/app/models/cart.rb定義車 StoreController#add_to_cart RAILS_ROOT:/ home/dave/work/depot 應用程序跟蹤|框架跟蹤|全面跟蹤 /usr/lib/ruby/1.8/active_support/dependencies.rb:426:in load_missing_constant' /usr/lib/ruby/1.8/active_support/dependencies.rb:80:in const_missing ' /usr/lib/ruby/1.8/active_support/dependencies.rb:92:in const_missing' /usr/lib/ruby/1.8/active_support/dependencies.rb:437:in load_missing_constant' 在/ usr/LIB /紅寶石/ 1.8/active_support/dependencies.rb:96:在const_missing' /home/dave/work/depot/app/controllers/store_controller.rb:14:in find_cart ' /home/dave/work/depot/app/controllers/store_controller.rb:8:in`add_to_cart' 請求 參數: {」 authenticity_token 「=>」 38s45mRICYPJ7dw + Z/rlcBnQN7T8ZwfEThzUTFUrjeM =」, 「ID」=> 「3」} 顯示會話轉儲 響應 接頭: { 「內容類型」=> 「」, 「緩存控制」 =>「no-cache」}

def add_product(product) 
    current_item = @items.find {|item| item.product == product} 
    if current_item 
     current_item.increment_quantity 
    else 
     @items << CartItem.new(product) 
    end 
    end 

我已經在Google上進行過搜索,並且類似的錯誤似乎與utf-8編碼有關。我用Gedit將文件保存爲西文(ISO 8859-15)編碼,並沒有什麼區別。我也重新輸入Vi中的程序無濟於事。每次我做出更改時,我都停止並重新啓動了服務器,並且還輸入了db:sessions:清除到終端中。

我很難過。有任何想法嗎?

回答

0

檢查您的應用程序/模型/ cart.rb,它應該是這樣的

 

class Cart < ActiveRecord::Base 

#stuff here 
end 

確保了這一點。

1

當加載的文件出現錯誤時,容易出現此錯誤。摸不着頭腦的一種方法是運行:

ruby script/console 

...然後:

Cart 

這應該要麼加載模型確定,或輸出更多有用的錯誤。