Gerard Petersen
2006-Jan-28 09:43 UTC
[Rails] DRY conflict with "Updated at" "Created at" "Deleted at" in view
Hi all, Are there any helpers or so for listview routines that suppres the three above mentioned columns? I''m currently exploring something like the code below. But it feels like I''m doing Rails'' work. # just for test purposes <div id="debug"> <% for col in Product.columns.map %> <%= col.name %> - <%= col.type %><br/> <% end %> </div> Skip if ... well, you know ... <% for column in Product.columns.map %> <% next if column.name == ''id'' %> <% next if column.name ~= ''_id'' %> <% next if column.name == ''created_at'' %> <% next if column.name == ''deleted_at'' %> <% next if column.name == ''contact_id'' %> Thanx! Gerard. -- "Who cares if it doesn''t do anything? It was made with our new Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..." My $Grtz =~ Gerard; ~ :wq!
James Adam
2006-Jan-28 10:00 UTC
[Rails] DRY conflict with "Updated at" "Created at" "Deleted at" in view
Rather than interacting with the Product model in your view, you should be selecting the columns to display from the controller: def list hidden_columns = ["created_at", "updated_at", ....] @columns = Product.content_columns.delete_if { |c| hidden_columns.include?(c.name) } end .. and then iterate over @columns rather than Product.columns in your view. - james On 1/28/06, Gerard Petersen <mailing@gp-net.nl> wrote:> Hi all, > > Are there any helpers or so for listview routines that suppres the three above > mentioned columns? I''m currently exploring something like the code below. But > it feels like I''m doing Rails'' work. > > # just for test purposes > <div id="debug"> > <% for col in Product.columns.map %> > <%= col.name %> - <%= col.type %><br/> > <% end %> > </div> > > Skip if ... well, you know ... > <% for column in Product.columns.map %> > <% next if column.name == ''id'' %> > <% next if column.name ~= ''_id'' %> > <% next if column.name == ''created_at'' %> > <% next if column.name == ''deleted_at'' %> > <% next if column.name == ''contact_id'' %> > > Thanx! > > Gerard. > > > > -- > "Who cares if it doesn''t do anything? It was made with our new > Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..." > > My $Grtz =~ Gerard; > ~ > :wq! > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Gerard Petersen
2006-Jan-28 10:29 UTC
[Rails] DRY conflict with "Updated at" "Created at" "Deleted at" in view
James, Brilliant tip, that way I''m also not avoiding the regular data access using the content_column instead of the columns(.map) like now. I realise that I''m still doing stuff in views that can(read: must) be done in models. This helps, Thanx a lot! Gerard. On Saturday 28 January 2006 10:59, James Adam tried to type something like:> Rather than interacting with the Product model in your view, you > should be selecting the columns to display from the controller: > > def list > hidden_columns = ["created_at", "updated_at", ....] > @columns = Product.content_columns.delete_if { |c| > hidden_columns.include?(c.name) } > end > > .. and then iterate over @columns rather than Product.columns in your view. > > - james > > On 1/28/06, Gerard Petersen <mailing@gp-net.nl> wrote: > > Hi all, > > > > Are there any helpers or so for listview routines that suppres the three > > above mentioned columns? I''m currently exploring something like the code > > below. But it feels like I''m doing Rails'' work. > > > > # just for test purposes > > <div id="debug"> > > <% for col in Product.columns.map %> > > <%= col.name %> - <%= col.type %><br/> > > <% end %> > > </div> > > > > Skip if ... well, you know ... > > <% for column in Product.columns.map %> > > <% next if column.name == ''id'' %> > > <% next if column.name ~= ''_id'' %> > > <% next if column.name == ''created_at'' %> > > <% next if column.name == ''deleted_at'' %> > > <% next if column.name == ''contact_id'' %> > > > > Thanx! > > > > Gerard. > > > > > > > > -- > > "Who cares if it doesn''t do anything? It was made with our new > > Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..." > > > > My $Grtz =~ Gerard; > > ~ > > > > :wq! > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-- "Who cares if it doesn''t do anything? It was made with our new Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..." My $Grtz =~ Gerard; ~ :wq!
Gerard Petersen
2006-Jan-28 10:59 UTC
[Rails] DRY conflict with "Updated at" "Created at" "Deleted at" in view
James, Ik misspoke myself in the pevious mail. Where I said to use it in the model (still a bit of a newbie I guess). I works like a charm in the controller. So the next Q (as you probably guess): Shouldn''t stuff like this belong in the model since it''s alteration of data (imho) not on an application flow kind of level? Tnx n Grtz Gerard On Saturday 28 January 2006 10:59, James Adam tried to type something like:> hidden_columns = ["created_at", "updated_at", ....] > ? ? ? @columns = Product.content_columns.delete_if { |c| > hidden_columns.include?(c.name) }-- "Who saysif it doesn''t do anything? It was made with our new RubyOnRails process ..." My $Grtz =~ Gerard; ~ :wq!