You can override options_for_association like you do with 
options_for_association_conditions

def options_for_association(association)
   available_records = association_options_find(association, 
options_for_association_conditions(association))
   available_records ||= []
   available_records.sort{|a,b| a.to_label <=> b.to_label}.collect { |model| [ 
model.to_label, model.id ] }
end

You can use something like this:
def options_for_association(association)
  if association.name == :category
     available_records = association_options_find(association, 
options_for_association_conditions(association))
     available_records ||= []
     available_records.sort{|a,b| a.to_label <=> b.to_label}.collect { |model| 
[ model.to_label, model.id ] }
  else
    super
  end
end

You can change the line which does the sorting

El Tuesday 02 September 2008 08:37:11 greghauptmann escribió:
> but I'm filtering on the records for one of the associations, and
> using the helper method "options_for_association_conditions"?  So it
> seems that the output of this method is for the ":conditions"..... So
> my "app/helpers/transaction_helper.rb" file looks like the below.
> Again my aim again is to get sorting on the drop down list for this
> "category" association...
>
> ==========================
> module TransactionHelper
>   def category_column(record)
>     Category.find(:all, :conditions => 'active = true')
>   end
>
>   def options_for_association_conditions(association)
>     if association.name == :category
>       ['active = 1 OR active is null']
>     else
>       super
>     end
>   end
>
> end
> ==========================
>
> On Sep 2, 2:14 pm, Sri Sri <[EMAIL PROTECTED]> wrote:
> > Try :order.
> > ....find(:all, :conditions => "", :order => "")
> >
> > greghauptmann wrote:
> > > thanks for this thread re how to filter down the number of records in
> > > a SELECT.    Is there a way however to be able to modify the SORT
> > > ORDER of the pull down list?   I tried putting a "order by" in the
> > > options_for_association_conditions however the SQL generated doesn't
> > > work, as it is creating a "where( xxx )" in brackets.
> > >
> > > Any ideas how to get sorting on a field drop down list for an
> > > association working?  (i.e. without having to do a full field
> > > override)
> > >
> > > tks


-- 
Sergio Cambra .:: entreCables - Symbol Servicios Informáticos S.L. ::.
Nicolás Guillén 6, locales 2 y 3. 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) [EMAIL PROTECTED]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" 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/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---

  • Re... greghauptmann
    • ... Sri Sri
    • ... Sri Sri
      • ... greghauptmann
        • ... Sri Sri
        • ... Sergio Cambra .:: entreCables - Symbol Servicios Informáticos S.L. ::.
    • ... omer

Reply via email to