Closed GoogleCodeExporter closed 9 years ago
When you call exclude or add in config.action.columns, columns are copied from
config.columns, so weights set after that call aren't used.
Original comment by sergio.c...@gmail.com
on 1 Mar 2010 at 8:56
[deleted comment]
(removed previous comment)
Sergio,
Thanks for your response!
So is the following correct?
* weights are useful when using config.cache_classes = false, because column
exclude
and re-add retain the weight, so the columns stay in the right order.
* If using config.cache_classes = true, weights are only useful prior to a
column
exclude and re-add. After a column re-add, if using config.cache_classes =
true, you
must redefine config.columns after the re-add of the column?
Thanks for all of your work on active scaffold. It is extremely useful!
Gary
Original comment by garyswea...@gmail.com
on 1 Mar 2010 at 2:28
Sergio,
As a workaround for weights not working when config.cache_classes = false, I
tried
specifying active_scaffold_config.columns = [ :my_first_column_name,
:my_second_column_name, :my_third_column_name, :my_fourth_column_name ] after
the
column exclude and re-add, and it doesn't work.
Note that I'm trying to do active_scaffold_config.list.columns.exclude (symbol
name
of column) and active_scaffold_config.list.columns.add (symbol name of column)
in a
method called by the before_filter and then doing
active_scaffold_config.columns = [
:my_first_column_name, :my_second_column_name, :my_third_column_name,
:my_fourth_column_name ].
Could you provide a workaround to set column order from method called by a
before_filter?
Best Regards,
Gary
Original comment by garyswea...@gmail.com
on 1 Mar 2010 at 8:36
Issue 733 has been merged into this issue.
Original comment by sergio.c...@gmail.com
on 2 Mar 2010 at 9:16
The only difference with caching classes is changes are remembered for next
request:
before_filter :add_column
def add_column
active_scaffold_config.list.columns << :a_column if some_condition
end
That before_filter add a column when some_condition is true, but after adding
it in
production environment (config.cache_classes enabled), it will be shown in next
requests, but in development mode, without caching classes, column only will be
shown when some_condition is true, because class is loaded in each request.
That's
only to ease changing code in development without restarting the server, caching
classes should always be enabled in production.
You can try copying config.columns._inheritable at beginning in before filter,
and
after excluding the columns. Instead of:
active_scaffold do |config|
[set weights]
config.list.columns.exclude :c1, :c2
end
def custom_before_filter
if condition
active_scaffold_config.list.columns.exclude :a
active_scaffold_config.list.columns << :b
else
active_scaffold_config.list.columns.exclude :b
active_scaffold_config.list.columns << :a
end
end
use this:
def custom_before_filter
active_scaffold_config.list.columns = active_scaffold_config.columns._inheritable
active_scaffold_config.list.columns.exclude :c1, :c2
if condition
active_scaffold_config.list.columns.exclude :a
else
active_scaffold_config.list.columns.exclude :b
end
end
Original comment by sergio.c...@gmail.com
on 2 Mar 2010 at 9:23
Sergio,
Thanks so much! That workaround worked for us with config.cache_classes enabled
or
disabled.
I blogged your solution here as well as additional notes:
http://stufftohelpyouout.blogspot.com/2010/03/activescaffold-and-column-order.ht
ml
The only additional thing I could think of to say is that this workaround would
seem
to only be a good option for those that don't need to accumulate column
additions and
exclusions during the session, since it is resetting the columns to their
original state.
Thanks again so much!
Gary
Original comment by garyswea...@gmail.com
on 2 Mar 2010 at 3:39
When you are changing columns per-request, in production you never know what is
the
columns state, so you always have to exclude all columns you don't want, and add
columns you want. So the best way is resetting columns and exclude some of
them, or
setting the columns array.
If we move to store changes in instance variables in order not to modify class
variables, you will always have the same state and it will be easier. Also AS
would
be thread safe with that change probably, but it's hard and it's not my priority
ATM.
Original comment by sergio.c...@gmail.com
on 3 Mar 2010 at 8:57
Could you add that article to the wiki?
Original comment by sergio.c...@gmail.com
on 3 Mar 2010 at 9:00
Sergio,
I just added some info and the links to "API: Core" here (
http://wiki.github.com/activescaffold/active_scaffold/api-core ) under the
"columns
local" section. Let me know if I should put it somewhere else or make additional
edits. Thanks again for your help!
Original comment by garyswea...@gmail.com
on 3 Mar 2010 at 12:25
Original issue reported on code.google.com by
garyswea...@gmail.com
on 26 Feb 2010 at 9:44Attachments: