Hi everybody..I'm trying follow the book "clone internet application
with ruby" but I get many errors when I try run it...in the twitter
clone example this is my code:

DataMapper.setup( :default, "sqlite3://#{Dir.pwd}/mydb.db" )


class User
  include DataMapper::Resource

  property :id,         Serial
  property :email,      String, :length => 255
  property :nickname,   String, :length => 255
  property :identifier, String, :length => 255
  property :photo_url,  String, :length => 255

  has n, :chirps
  has n, :direct_messages, :model => "Chirp"
  has n, :relationships

  has n, :followers, :through => :relationships, :model =>
"User", :child_key => [:user_id]
  has n, :follows, :through => :relationships, :model => "User", :via
=> :user, :child_key => [:follower_id]

  def self.find(identifier)
    u = first(:identifier => identifier)
    u = new(:identifier => identifier) if u.nil?
    return u
  end

  def displayed_chirps
    chirps = []
    chirps += self.chirps.all(:recipient_id => nil, :limit =>
10, :order => [:created_at.desc]) # don't show direct messsages
    self.follows.each do |follows| chirps +=
follows.chirps.all(:recipient_id => nil, :limit => 10, :order =>
[:created_at.desc]) end if @myself == @user
    chirps.sort! { |x,y| y.created_at <=> x.created_at }
    chirps[0..10]
  end


end

class Relationship
  include DataMapper::Resource

  property :user_id, Integer, :key => true
  property :follower_id, Integer, :key => true
  belongs_to :user, :child_key => [:user_id]
  belongs_to :follower, :model => "User", :child_key => [:follower_id]


end

class Chirp
  include DataMapper::Resource

  property :id, Serial
  property :text, String, :length => 140
  property :created_at,  DateTime
  belongs_to :recipient, :model => "User", :child_key =>
[:recipient_id]
  belongs_to :user

  before :save do
    case
    when starts_with?('dm ')
      process_dm
    when starts_with?('follow ')
      process_follow
    else
      process
    end
  end

  # general scrubbing of chirp
  def process
    # process url
    urls = self.text.scan(URL_REGEXP)
    urls.each { |url|
      tiny_url = open("http://tinyurl.com/api-create.php?
url=#{url[0]}") {|s| s.read}
      self.text.sub!(url[0], "<a href='#{tiny_url}'>#{tiny_url}</a>")
    }
    # process @
    ats = self.text.scan(AT_REGEXP)
    ats.each { |at| self.text.sub!(at, "<a href='/
#{at[2,at.length]}'>#{at}</a>") }
  end

  # process direct messages
  def process_dm
    self.recipient = User.first(:email => self.text.split[1])
    self.text = self.text.split[2..self.text.split.size].join(' ') #
remove the first 2 words
    process
  end

  # process follow commands
  def process_follow
    Relationship.create(:user => User.first(:email =>
self.text.split[1]), :follower => self.user)
    throw :halt # don't save
  end

  def starts_with?(prefix)
    prefix = prefix.to_s
    self.text[0, prefix.length] == prefix
  end


end

DataMapper.auto_migrate!

when I run it I get

   /usr/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/
property_set.rb:161:in `initialize': undefined method `name' for
nil:NilClass (NoMethodError)
        from /usr/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/
property_set.rb:161:in `map'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/
property_set.rb:161:in `initialize'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/
associations/many_to_many.rb:23:in `new'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/
associations/many_to_many.rb:23:in `child_key'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/model.rb:
793:in `assert_valid'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/model.rb:
792:in `each'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/model.rb:
792:in `assert_valid'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/model.rb:
791:in `each'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/model.rb:
791:in `assert_valid'
        from /usr/lib/ruby/gems/1.8/gems/dm-migrations-1.0.2/lib/dm-
migrations/auto_migration.rb:128:in `auto_migrate!'
        from /usr/lib/ruby/gems/1.8/gems/dm-migrations-1.0.2/lib/dm-
migrations/auto_migration.rb:45:in `send'
        from /usr/lib/ruby/gems/1.8/gems/dm-migrations-1.0.2/lib/dm-
migrations/auto_migration.rb:45:in `repository_execute'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/support/
descendant_set.rb:68:in `each'
        from /usr/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/support/
descendant_set.rb:67:in `each'
        from /usr/lib/ruby/gems/1.8/gems/dm-migrations-1.0.2/lib/dm-
migrations/auto_migration.rb:44:in `repository_execute'
        from /usr/lib/ruby/gems/1.8/gems/dm-migrations-1.0.2/lib/dm-
migrations/auto_migration.rb:22:in `auto_migrate!'
        from /usr/lib/ruby/gems/1.8/gems/dm-constraints-1.0.2/lib/dm-
constraints/migrations.rb:11:in `auto_migrate!'
        from /root/RubymineProjects/twitsin/twitter.rb:194
        from -e:1:in `load'
        from -e:1


I know Datamappers has been many changes but I don't know what code is
still valid yet and which has changed....if anybody can help me thanks

greetings from Italy

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to