Trouble setting up columns in a before_filter

5 views
Skip to first unread message

Daniel E

unread,
May 10, 2007, 7:32:58 AM5/10/07
to ActiveScaffold : Ruby on Rails plugin
I'm trying to use a before filter to dynamically configure the columns
to be displayed in the list action based on details available in the
request. my original method looked something like this:

active_scaffold :something do |config|
config.list.columns = [ :initial, :columns ]
end

def update_table_config
get_columns_for_run(params[:run_id]).each do |column_name|
active_scaffold_config.list.columns.add column_name
end

This was working but it had one dramatic bug. Each subsequent request
of the controller caused the set of columns to be re-added.
I thought I could solve this by storing a constant with the base set
of columns then just use columns = before my .add.

DEFAULT_COLUMNS = [ :initial, :columns ]
active_scaffold :something do |config|
config.list.columns = DEFAULT_COLUMNS
end

def update_table_config
active_scaffold_config.list.columns = DEFAULT_COLUMNS
get_columns_for_run(params[:run_id]).each do |column_name|
active_scaffold_config.list.columns.add column_name
end


But I get an odd exception when I try this. Unfortunately, I'm not at
the office right now so I can't give the exact error, but it was
something to do with active_scaffold.class or some-such. :(

I was hoping someone might be able to just look at this code and
clearly see some thing that I did wrong or suggest the right way to do
it.
If it doesn't make enough sense, I'll post the actual code snippits
and full error message when I get into the office.

Thanks, Daniel

Lance Ivy

unread,
May 10, 2007, 11:59:23 AM5/10/07
to actives...@googlegroups.com
Also try:

active_scaffold_config.list.columns.add(column_name) unless active_scaffold_config.list.columns.include?(column_name)

Daniel E

unread,
May 10, 2007, 8:13:04 PM5/10/07
to ActiveScaffold : Ruby on Rails plugin
What I found is that you can't use active_scaffold_config.list.columns
= [...] in a before_filter. You can only use .add and .exclude. I
ended up doing
active_scaffold_config.list.columns.each { |col|
active_scaffold_config.list.columns.exclude col.name }
and then adding the new columns after that loop.

On May 10, 11:59 am, "Lance Ivy" <l...@cainlevy.net> wrote:
> Also try:
>
> active_scaffold_config.list.columns.add(column_name) unless
> active_scaffold_config.list.columns.include?(column_name)
>

Reply all
Reply to author
Forward
0 new messages