Hello,

I've solved problem with following code:

<def tag="select-many-in-contract">
<select-many merge options="&this_field_reflection.klass.all(:conditions =>this.conditions).select {|x| can_view?(x) && (x.respond_to?(:global) && x.global?) ? true : x.contract.id == this_parent.contract.id }"/>
</def>

<extend tag="form" for="Device">
  <old-form merge>
<field-list: fields="name, device_type, networked, buy_date, warranty_date, supplier, info, groups, config_klasses, config_params, network_interfaces">
      <config-params-view:>
        <input-many fields="name, value"/>
      </config-params-view:>
      <groups-view:>
        <select-many-in-contract/>
      </groups-view:>
    </field-list:>
  </old-form>
</extend>

groups is "has_many :through" association.

cheers


Wiadomość napisana w dniu 2010-02-13, o godz. 03:45, przez Mike S.:

Hi. I've been struggling with this as well. Another post suggested
using the the edit-page view to modify the select-many options, i.e.:

<select-many:devices options="&@this.contract.groups"/>

I've tried this structure outside of the <edit-page> tags in
"edit.dryml" and it does the proper filtering, but the changes are not
saved (assuming because it's outside of the <edit-page> tag).

However, I cannot get this to work _inside_ the <edit-page> tags, and
I don't know why. I also tried your method of modifying the
"application.dryml" file to include this change, but that failed also.

Modifying the <select-many> tag provides the desired filtering. I'm
just at a loss as to where/how to insert it to make it operate
correctly. I

---
Thx
Mike


On Feb 12, 12:10 pm, Grzegorz Marszałek <[email protected]> wrote:
Hello!

I'm trying to figure out, how to limit choices using select-many tag.
Code is like this:

class Contract < ActiveRecord::Base
...
   has_many :devices
   has_many :networks
   has_many :groups
...
end

class Device < ActiveRecord::Base
...
   belongs_to :contract
   has_many :group_memberships
has_many :groups, :through => :group_memberships, :accessible => true
...
end
class GroupMembership < ActiveRecord::Base
...
   belongs_to :group
   belongs_to :device
...
end
class Group < ActiveRecord::Base
...
   belongs_to :contract
   has_many :group_memberships
   has_many :devices, :through => :group_memberships,  :accessible =>
true
end

and in application.dryml:
<extend tag="form" for="Group">
   <old-form merge>
     <field-list: fields="name, devices"/>
   </old-form>
</extend>

Now - it's working fine, but each time I edit Group I get select field
with ALL devices. My goal is to limit this list to devices belonging
to THE SAME contarct, as group. I've try something like this in Group
class:

   has_many :devices, :through => :group_memberships,  :accessible =>
true, :conditions => ['contract_id = ?', self.contract.id]

But it doesn't work as I though it would :(

Any ideas or clues? :)
---
Grzegorz Marsza³ek
[email protected]

---
Grzegorz Marszałek
[email protected]


--
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.

Reply via email to