I settled with this solution at the top of each controller where I
want schema order:
self.model.columns.each_with_index { |c, i| config.columns
[c.name.to_sym].weight = i if config.columns[c.name.to_sym] }
which is a mix of these three snippets found elsewhere in this
newsgroup:
config.columns[:last_name].weight = -10
conf.columns = self.model.columns.collect{ |c| c.name.to_s.chomp
('_id') }
val.each_with_index { |c, i| @columns[c.to_sym].weight = i }
Now at least I have what I want. Surely I will thank local gurus who
tell me of better ways.
Interestingly, I came up with this solution after writing above post.
Once again, writing the idea clarifies the idea.On 9 jul, 19:21, Kerry Foley <[email protected]> wrote: > Regarding your second issue; You could just exclude columns that you > don't want. That way new fields will be picked up automatically. > > config.list.columns.exclude :notes > > Regards, > Kerry > > otto wrote: > > I have seen many posts about the current default order of > > config.columns as being alphabetic and also many posts about asking to > > revert this default to schema order as it was before. Not wanting to > > go into a flame war about which is more convenient or if changing it > > breaks current apps, is there a way to "choose" schema order even if > > alpha is the default? > > I have read posts and wiki about column weight, but I do not > > understand how to implement schema order with the weight attribute > > without listing fields programmatically. I want the controller to know > > the lesser the better about the model. > > Given schema order c_field, b_field, a_field > > current default AS will set config.columns as > > [:a_field, :b_field, :c_field] > > I know I can set schema order manually with weight attribute by doing > > config.columns[:c_field].weight = 1 > > config.columns[:b_field].weight = 2 > > config.columns[:a_field].weight = 3 > > to get above schema order > > I know I also can set schema order manually by doing > > config.columns = [:c_field, :b_field, :a_field] > > BUT as ActiveScaffold worked in the past defaulting to schema order, > > my controller did not need to know these many model details. Given my > > understanding of current AS, this will also break when I add new > > fields to the model, because I will be required to "list" them in the > > controller to get schema order. > > It never bothered me before but right now I am using 50-70 fields > > models so reordering them is getting cumbersome. Please don't tell me > > to normalize, they already are. They have so many fields because the > > app is a statistical data gathering app. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
