DRY conflict with "Updated at" "Created at" "Deleted at" in

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

<% for col in Product.columns.map %> <%= col.name %> - <%= col.type %>
<% end %>

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!

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

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 A. tried to type something
like:

<% next if column.name == 'deleted_at' %> Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..."

Rails mailing list
[email protected]
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!

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 A. 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!