On Tue, Dec 9, 2008 at 7:58 AM, firman syah <[EMAIL PROTECTED]> wrote: > Akhirnya ada juga yang merespon "pertanyaan aneh ini" :) > > Nah, justru itu. Jujur, karena masih newbie, kemarin cuma ngikutin example > aja. > Mungkin karena versi rails di example "kuno". > Gimana mas, cara meloadnya? >
seluruh model akan di-load secara otomatis by default, jd ndak perlu load-load-an ^_^ > Beikut isi model yang akan di Load: > purchase.rb: > >> class Purchase < ActiveRecord::Base >> belongs_to :item >> >> def self.buy_one(item) >> purchase = self.new >> purchase.item = item >> purchase.quantity = 1 >> purchase.price = item.price >> return purchase >> end >> >> end >> > > cart.rb : > >> class Cart >> attr_reader :purchase >> attr_reader :total >> >> def initialize >> @purchase = [] >> @total = 0.0 >> end >> >> def add_purchase(item) >> @purchases << Purchase.buy_one(item) >> @total += item.price >> end >> >> end >> > > buy_controller: > >> class BuyController < ApplicationController >> def index >> @items = Item.return_items >> end >> >> def add >> @items = Item.find(params[:id]) >> @cart = get_cart >> @Cart.add_purchase(item) >> session[:shopping_cart] = @cart >> redirect_to(:action => 'display_cart') >> end >> >> def display_cart >> @cart = get_cart >> @purchases = @cart.purchases >> @total = @cart.total >> end >> >> private >> def get_cart >> if session[:shopping_cart] >> return session[:shopping_cart] >> else >> return Cart.new >> end >> end >> >> end >> > > TerimaKasih.. :) > > On Tue, Dec 9, 2008 at 7:33 AM, adit <[EMAIL PROTECTED]> wrote: > >> sy ingin tanya, kenapa mas Firman ingin me load seluruh helper di >> application.rb ? >> >> apakah tidak ada jalan lain sehingga ingin me-load seluruh helper >> sehingga available di seluruh controller ? >> >> dan lagian seluruh model bisa langsung diakses diseluruh app tanpa >> perlu di load secara ekplisit >> >> >> On Wed, Dec 3, 2008 at 4:50 PM, firman syah >> <[EMAIL PROTECTED]<abanggeh%40gmail.com>> >> wrote: >> > Mas2... >> > mo tanya, kalau preloaded class taruhnya dimana? >> > saya coba masukin di bawah model, trus diload sebagai module di >> application >> > controller. Ternyata malah error. >> > >> > ./app/models: >> > cart.rb item.rb purchase.rb >> > >> > application.rb: >> > class ApplicationController < ActionController::Base >> > helper :all # include all helpers, all the time >> > model :cart >> > model :purchase >> > ..... >> > >> > error: >> > => Booting WEBrick... >> > /~home/Rails/store/app/controllers/application.rb:6: undefined method >> > `model' for ApplicationController:Class (NoMethodError) >> > from >> > >> >> /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:216:in >> > `load_without_new_constant_marking' >> > from >> > >> >> /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:216:in >> > `load_file' >> > from >> > >> >> /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:355:in >> > `new_constants_in' >> > from >> > >> >> /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:215:in >> > `load_file' >> > from >> > >> >> /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:96:in >> > `require_or_load' >> > from >> > >> >> /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:61:in >> > `depend_on' >> > from >> > >> >> /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:457:in >> > `require_dependency' >> > from >> > >> >> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/dispatcher.rb:18:in >> > `define_dispatcher_callbacks' >> > ... 25 levels... >> > from >> > /usr/local/lib/ruby/gems/1.8/gems/rails-2.1.2/lib/commands/server.rb:39 >> > from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in >> > `gem_original_require' >> > from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in >> > `require' >> > from script/server:3 >> > >> > thanks.. :) >> > >> > [Non-text portions of this message have been removed] >> > >> > >> >> -- >> blog : http://adityakircon.blogsome.com >> ym : adit.prawirasoft >> skype : adit_skype >> >> i continue to fight, i continue to FIGHT (O2 - Orange Range) >> >> > > [Non-text portions of this message have been removed] > > -- blog : http://adityakircon.blogsome.com ym : adit.prawirasoft skype : adit_skype i continue to fight, i continue to FIGHT (O2 - Orange Range)

