Here was my solution.  I couldn't get the :conditions to accept a parameter. 
 It may be possible but was beyond my current skill set.

First remember I model is essentially

Locations <-> Materials -> Samples

And I'm wanting to add locations to samples but only locations where the 
materials exist at.

First I added a scope to Locations to find only those locations that have 
the given material

  scope :material_locations, lambda { |m| {
      :joins => :materials,
      :conditions => ["materials.id = ?", m.id]
  } }

Next I edited the show for materials since I'm using the embedded form to 
add new samples to materials via an auto_actions_for :material, [:create] in 
the samples controller.  I needed to get all the locations the material 
being samples is at.

  def show
    hobo_show do
      @material_locations = Location.material_locations(this)
    end
  end 

I had to do the same thing to the sample controller edit method for when the 
user edits a sample 

  def edit
    hobo_show do
      @material_locations = Location.material_locations(this.material)
    end
  end

I then edited the form for samples to limit the select-one list for the 
locations to use my custom lists of locations.  Note I also added 
a costume text-method to location since a locations could be repeated and 
the user wouldn't be able to tell one from another.  location_space includes 
the locations parent name to help distinguish them.

      <location-view:>
        <select-one options="&@material_locations" 
text-method="location_space" include-none="&false"/>
      </location-view:>

Now the user can only add locations to samples where the materials already 
exist at.

Bob


-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/hobousers/-/fCc82wTe1-cJ.
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.

Reply via email to