class Sample < ActiveRecord::BaseAs you can see the conditions are hard coded to material_id 2. What I want is the ID of the material belongs_to association. I know this looks a bit confusing as to why I would want that so I'll try to explain.
hobo_model # Don't put anything above this
SAMPLE_TYPES = HoboFields::Types::EnumString.for(:asbestos, :lead, :pcb)
fields do
sample_type Sample::SAMPLE_TYPES
positive :boolean
result :string
timestamps
end
inline_booleans true
belongs_to :material
belongs_to :location, :class_name => "LocationMaterial", :foreign_key => :location_id, :conditions => ["location_materials.material_id = ?", 2]
...
end
El 05/08/11 19:29, Bob Sleys escribi�:
>
> Now samples also need to be tied back to the location they where taken from
> IE I need to know not only what material was samples but where it came
> from. I also need to restrict the location selection list when
> adding/editing samples to only locations where the material exists. Can't
> sample a material where it doesn't exist after all.
Interesting issue. In a somewhat similar case I when with a custom
action in the controller:
- - The location list is empty by default.
- - The user selects a material. A Hobo Ajax call is triggered, sending
the ID of the material.
- - The location list is updated.
It's not DRY at all, so if you find a nice solution please post :).
Regards,
Ignacio
- --
Ignacio Huerta Arteche
http://www.ihuerta.net
Tel�fono: 0034 645 70 77 35
Email realizado con software libre
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk4+vBwACgkQBPlUJ6RHaOQHzgCg98V+dR6Br2ffrVd/8ZffY/g1
XLgAn1LiL6114+F/nW5pVOr5jzsbEPBB
=o3C4
-----END PGP SIGNATURE-----
scope :material_locations, lambda { |m| {
:joins => :materials,
:conditions => ["materials.id = ?", m.id]
} }
def show
hobo_show do
@material_locations = Location.material_locations(this)
end
end
def edit
hobo_show do
@material_locations = Location.material_locations(this.material)
end
end
<location-view:>
<select-one options="&@material_locations" text-method="location_space" include-none="&false"/>
</location-view:>