Gabriele Tassoni
unread,May 21, 2009, 10:07:52 AM5/21/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Hobo Users
Hi,
I'm experimenting with the ownership in hobo, the app has an invoice
module and a bank module, both with the ownership in place, thus:
class Bank < ActiveRecord::Base
hobo_model # Don't put anything above this
# SOME CODE
# --- Relations --- #
belongs_to :owner, :class_name => "User", :creator => true
has_many :invoices, :dependent => :destroy
# SOME CODE
end
and for the invoice:
class Invoice < ActiveRecord::Base
hobo_model # Don't put anything above this
# SOME CODE
belongs_to :bank
belongs_to :owner, :class_name => "User", :creator => true
# SOME CODE
end
the users.rb has:
has_many :banks, :class_name => "Bank", :foreign_key =>
"owner_id", :dependent => :destroy
has_many :invoices, :class_name => "Invoice", :foreign_key =>
"owner_id", :dependent => :destroy
what I would expect is that the index of both invoices and banks just
shows the current_user's invoices and banks, this is easy, before
reading the Agility tutorial, I redifined the index method like this
(i.e. for Invoice):
def index
hobo_index Invoice.owned_by(current_user), :per_page => 10, :order
=> "issued_on DESC, number DESC"
end
As you can see I had to define a owned_by named_scope for all the
models, not really dry, but it worked.
after reading the tutorial I understood that the correct way would be
to redifine part of the dryml of the index pages, making the
collection look like this:
<collection:invoices with="¤t_user"/>
I have to test it, but it looks okay, now comes the problem, I can't
understand the right way to achieve the same behaviour for select
boxes that represent and association, I mean, if I create a new
Invoice, I have a select that lists the banks one could choose, but I
can see all the banks, even the ones owned by a different user than
me... which is the right hobo/DRY way to achieve this? I don't think I
have to redefine the select tag... or do I have? °_°
And what wuold happen in the case of a has_many :through? I think I'm
missing something important, but can't see what it is!
Thank you
G.