On Jueves, 22 de Julio de 2010 00:48:28 dave smylie escribió:
> I'm using ActiveScaffold extensively over a legacy oracle schema.
> Mostly it works well, but one issue this legacy schema has introduced
> is that all the column names have  a standard prefix - eg, all the
> columns in the Company table have a prefix of comp_ (comp_id,
> comp_name etc)
>
> I have (seperate from ActiveScaffold) a method that sets up accessors
> for all of these automatically with the prefix's removed which works
> reasonably well.
>
> However, when using ActiveScaffold, the sortable? method returns false
> for these columns causing them to not be sortable by default (as they
> don't match the column names exactly I guess).
>
> This is easily remedied on an individual basis using sort_by. eg
>   config.columns[:name].sort_by :method => 'comp_name'
>
> Once that is specified, the native ActiveScaffold sorting works fine -
> however, I don't want to have to define this for every column in every
> active_scaffold block if I don't have to.
>
> The only way I can think of dealing with this is to alias the
> active_scaffold method and iterate thru config.column setting the
> sort_by after the call to the original method.
> Is there a cleaner/better way of setting a prefix for something like
> this to be checked or is this a reasonable approach?

No, ActiveScaffold can't guess your virtual columns are linked to a prefixed 
column.
You could iterate over real columns and configure unprefixed virtual columns:

active_scaffold do |config|
  [...]
end

active_scaffold_config.model.columns.each do |column|
  active_scaffold_config.columns[column.gsub(/^comp_/, '')].sort_by :sql => 
column
end

You can make a class method in ApplicationController which invoke that iteration

Or you can use prefixed_columns directly in ActiveScaffold and put i18n 
translations
in config/locales/en.yml to remove prefix from the label. Or remove prefix from 
the label
with a loop like above one.

-- 
Sergio Cambra .:: entreCables S.L. ::.
Mariana Pineda 23, 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.

Reply via email to