I'm getting an error when I try and use ViewHints and I'm not sure
what I'm doing wrong. A simple has_many/belongs_to relationship works
fine in a test application, but in the app I'm working on now, pretty
much any children declaration in the ViewHints causes the app to crash
without rendering anything to the screen. I seem to get one of two
errors, depending on the relationship I'm trying to set up.
#<NoMethodError: undefined method `name' for nil:NilClass>
or
#<NoMethodError: undefined method `klass' for nil:NilClass>
My models have become somewhat complex, I'll see if I can describe
what I'm trying to accomplish here before listing out the models.
We have Users, Locations, Orders, and Products. Join tables are
LocationProduct and ProductOrder.
* Users belong to a single Location called default_location.
* Locations have Products, and for each Product, they have minimum and
current levels. This is to keep track of each location's product
inventory.
* Locations have many Orders (There will be a sender and receiver
location for each order, so I can decrement/increment the product
counts and keep track of the location's inventory)
* Orders belong to a sender and a receiver (Users) (So I know who
placed the order and who the customer is)
* Orders have many Products
* Orders belong to a sender Location and receiver Location
* Products have many Orders (through the ProductOrders join table)
* Products have many Locations (through the LocationProducts join
table)
Sorry for hurting your brain. Well, it hurts mine at least. Anyway,
here are the model definitions:
class User < ActiveRecord::Base
hobo_user_model # Don't put anything above this
fields do
name :string, :required, :unique
email_address :email_address, :login => true
administrator :boolean, :default => false
customer :boolean, :default => true
employee :boolean, :default => false
timestamps
end
belongs_to :default_location, :class_name => "Location"
end
class Location < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
name :string
timestamps
end
has_many :users
has_many :products, :through => :location_product
has_many :orders
end
class Order < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
timestamps
end
belongs_to :sender, :class_name => "User"
belongs_to :receiver, :class_name => "User"
belongs_to :sender_location, :class_name => "Location"
belongs_to :receiver_location, :class_name => "Location"
has_many :product_orders, :accessible => true
has_many :products, :through => :product_orders, :accessible =>
false
end
class Product < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
name :string
code :integer
comments :text
discontinued :boolean
supplier :string
timestamps
end
has_many :product_orders
has_many :orders, :through => :product_orders, :accessible => false
has_many :locations, :through => :location_products, :accessible =>
true
end
class LocationProduct < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
minimum :integer
current :integer
timestamps
end
belongs_to :location
belongs_to :product
validates_presence_of :minimum
validates_presence_of :current
end
class ProductOrder < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
quantity :integer
timestamps
end
belongs_to :product
belongs_to :order
validates_presence_of :quantity
end
That's my setup so far. Now if I attempt to use any children
ViewHints at all, I get one of the two errors I mentioned above. For
instance:
class LocationHints < Hobo::ViewHints
children :users, :products, :orders
end
Gives this error:
Dec 08 11:24:14 -0800 2009: Read error: #<NoMethodError: undefined
method `name' for nil:NilClass>
/usr/lib/ruby/gems/1.8/gems/hobosupport-0.9.102/lib/hobo_support.rb:
29:in `safe_constantize'
/usr/lib/ruby/gems/1.8/gems/hobo-0.9.102/lib/hobo/view_hints.rb:39:in
`__instance_exec0'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/
core_ext/object/extending.rb:74:in `send'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/
core_ext/object/extending.rb:74:in `instance_exec'
/usr/lib/ruby/gems/1.8/gems/hobo-0.9.102/lib/hobo/view_hints.rb:21:in
`children'
/srv/inventory/app/viewhints/location_hints.rb:2
If it's inappropriate to post here for help with my models and this is
a problem with my model definitions, do please let me know where I
might find help (maybe a Rails group?) Thanks!
Brian
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" 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/hobousers?hl=en.