Forum: Ruby on Rails DRY conflict with "Updated at" "Created at" "Deleted at" in

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Gerard P. (Guest)
on 2006-01-28 11:45
(Received via mailing list)
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 A. (Guest)
on 2006-01-28 12:00
(Received via mailing list)
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
Gerard P. (Guest)
on 2006-01-28 12:31
(Received via mailing list)
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:
>
> > <div id="debug">
> >         <% next if column.name == 'deleted_at' %>
> > Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..."
>
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> 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 P. (Guest)
on 2006-01-28 13:01
(Received via mailing list)
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!
This topic is locked and can not be replied to.