Ruby學習總結

1 判斷浮點數的整數部分的長度(float.to_i.to_s.length)

#整數部分長度爲6
  protected
  def part_integer_length_must_be_six_at_most
    errors.add(:price,'part_integer_length_must_be_six_at_most') if  price.nil? || price.to_i.to_s.length > 6
  end


2 新增一個控制器後,需在config/routes目錄下新增一項

   如E:\develoToolsAndSoftWare\InstantRails-2.0-win\rails_apps\demo>ruby script/gener
ate controller store index  ,在routes新增map.resources :store



3 開發過程中遇到的問題:爲什麼有時候購物網站存在用戶購物車的數據突然沒有了

   答:在網站後臺,用戶購物的數據放在了seesion裏面,若此時後臺代碼更新,老的session購物車對象與新版本的源代碼無法相容,解決辦法就是把session數據清空,那麼用戶的購物車物品就會全部消失。




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章