Forum: Ruby on Rails Partials layouts

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.
Ead43bcb0202410540a6a7cee5955d46?d=identicon&s=25 Fresh Mix (giga)
on 2009-03-12 20:59
In partial I have something like this:

<% if @first == 'x' %>
xxx: <%= @data.xxx %>
yyy: <%= @data.yyy %>
<% else %>
yyy: <%= @data.yyy %>
xxx: <%= @data.xxx %>
<% end %>
zzz: <%= @data.zzz %>
qqq: <%= @data.qqq %>


Is there any better way to do this?

I don't like, that there are same lines 2 times.
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2009-03-12 21:21
(Received via mailing list)
On Mar 12, 2009, at 3:59 PM, Fresh Mix wrote:
> qqq: <%= @data.qqq %>
>
> Is there any better way to do this?
>
> I don't like, that there are same lines 2 times.
> --


Controller says:
   @order = [ 'xxx', 'yyy' ]

View:
<% @order.each do |a| %>
<%= a %>: <%= @data.send(a) %>
<% end %>
zzz: <%= @data.zzz %>
qqq: <%= @data.qqq %>

Or go all the way and:
   @order = ['xxx', 'yyy', 'zzz', 'qqq']

-Rob

Rob Biedenharn    http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
This topic is locked and can not be replied to.