From: Peter Ehrlich Date: 2009-08-20T08:17:36+09:00 Subject: Re: exercise in DRY So for anyone curious, here's how I wound up doing it: (no haml just because I'm too busy learning rails and ruby already :-) It probably could be made more dry, but this is pretty good and has the benefit of being written. I haven't included the controller, because its a bit more complex, dealing with different databases of anonymous and non-anonymous users.. ==== _agree_field.erb ==== <% #logger.debug "view agree: " + tweet.votedOn.to_s -%> <% if tweet.votedOn != nil -%> <% if tweet.votedOn == 1 #agree %> <% agree = "#{tweet.agree_count - 1} + 1" %> <% disagree = tweet.disagree_count.to_s %> <% elsif tweet.votedOn == 0 #disagree%> <% disagree = "#{tweet.disagree_count - 1} + 1" %> <% agree = tweet.agree_count.to_s -%> <% elsif tweet.votedOn == 2 #neutral -%> <% agree = tweet.agree_count.to_s -%> <% disagree = tweet.disagree_count.to_s %> <% end %> <%= agree %> – <%= disagree %> <% else -%> <%= link_to_remote('Agree', :update => "#{tweet.dom_id}_c", :url => "/tweets/agree/#{tweet.id}?agree=true") %> <%= link_to_remote('–', :update => "#{tweet.dom_id}_c", :url => "/tweets/agree/#{tweet.id}")%> <%= link_to_remote('Disagree', :update => "#{tweet.dom_id}_c", :url => "/tweets/agree/#{tweet.id}?agree=false")%> <% end -%> Cheers, --Peter -- Posted via http://www.ruby-forum.com/.