[Nitro] Help for Og Beginner

Bryan Soto bryan.a.soto at gmail.com
Fri Jan 6 02:30:58 EST 2006


Hi Gary,

Currently the best examples would be available at:

http://rubyforge.org/frs/?group_id=418

Check out spark, flare and the examples archive. They're all combinations of
Nitro and Og. Hopefully those will help.

Also,

db = Og.setup(               # <= changed
      :database => 'test',
      :store => :mysql,      # <= changed
      :user     => 'user',
      :password => 'password'
    )

Depending on your setup, you might need to add :socket => /path/to/socket or
:server => '127.0.0.1'

The basic idea is that Og will "enchant" your classes. So, for example, if
you were to make a database of members of your RUG, an Og model would be

class Member
  property :full_name, String  # String is default and can be omitted.
  property :skill_level, Fixnum
  property :email_address # Omitting the default

  validate_value :full_name   # See
http://www.cs.helsinki.fi/u/kaniemel/rdoc/glue/classes/Glue/Validation/ClassMethods.html#M000063
  validate_numeric :skill_level
  validate_inclusion :skill_level, :in => 1..10
  validate_unique :email_address # See
http://www.cs.helsinki.fi/u/kaniemel/rdoc/og/classes/Glue/Validation/ClassMethods.html#M000705
end

Then define your store:

Og.setup(               # <= changed
      :database => 'rug_members',
      :store => :mysql,      # <= changed
      :user     => 'user',
      :password => 'password'
    )

After which in code,

member = Member.new
member.full_name = 'Gary Wright'
member.email_address = "gary's email"
member.skill_level = 10

member.save

If any of the validations were to fail, they'd be available via

member.errors

where the could be iterated over

member.errors.errors.each do | field, msg|
  puts "#[field} had an error!: #{msg}"
end

Finding a single member via email address:

Member.find_by_email_address('an email address')  # => nil

or selecting a group by skill level:

Member.find_all_by_skill_leve(10) # => an array of members including Gary

I hope that's enough to give you a start and to understand the examples,
spark and flare. Currently though, this mailing list and irc, #nitro on
freenode, are the best places for info. Hopefully that will change soon. At
the very least, beginning with the next release, the rdoc should be built on
install.

Hope that helps and please don't hesitate to ask more questions.

Bryan



On 1/5/06, Gary Wright <gwtmp01 at mac.com> wrote:
>
>
> I've volunteered to learn and then share information about Og with
> my  local
> Ruby User's group next week.  I've had a hard time finding a simple Og
> example that actually works.  The standard tutorial says:
>
>         WARNING: This tutorial refers to an older version of Og. Many new
> and
>         exciting features were added in the meantime. Hopefuly this
> tutorial
>         will be updated soon.
>
> There must be a simple working example of Og somewhere?
>
> I've got the gem installed and by looking at the API docs I guessed that
> I needed to do something like:
>
> db = Og::Store.create(
>       :database => 'test',
>       :adapter  => 'mysql',
>       :user     => 'user',
>       :password => 'password'
>     )
>
> to establish a database connection but that just gets me:
>
>         undefined method `ogmanager' for Post:Class
>
> when I try to save an instance of Post.  (p.save)
>
> The tutorial uses Og::Database, which is not defined.
>
> Notes:
>     The default API link: http://www.nitrohq.com/rdoc/og/index.html
> fails with an error.
>     The alternate site: http://www.cs.helsinki.fi/u/kaniemel/rdoc/og/
> worked.
>     The 0.26.0 gem for og doesn't seem to build/install the rdocs
> correctly.
>     The Og FAQs are really just that: questions with no answers!
>
> I'm looking forward to playing with OG but I'd hoped to not have to
> read the source to do it.
>
> Can someone point me in the correct direction?
>
> I'm going to watch the videos later tonight...
>
> Gary Wright
>
>
>
>
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/nitro-general/attachments/20060106/844c9db5/attachment.html 


More information about the Nitro-general mailing list