From: Peter Ehrlich Date: 2009-08-19T01:33:50+09:00 Subject: exercise in DRY I have some simple code for a thumbs up/thumbs down functionality. Clicking "agree" sends an ajax count to increase the agree field by one, clicking disagree increases the "disagree" count by one. The text returned is both values with the updated one shown as "oldval +1" Is there any good way to make this pretty? The most I can think of is a boolean argument specifying agree/disagree, but that doesn't really make things any simpler :-/ Thanks! --Peter def agree tweet = tweet.find(params[:id]) tweet.agree_count += 1 render :text => consensus_agree(tweet.agree_count, tweet.disagree_count) end def disagree tweet = tweet.find(params[:id]) tweet.disagree_count += 1 render :text => consensus_agree(tweet.agree_count, tweet.disagree_count) end private def consensus_agree(agree_count, disagree_count) "#{agree_count -1} + 1#{disagree_count}" end def consensus_disagree(agree_count, disagree_count) "#{agree_count}#{disagree_count -1} + 1" end -- Posted via http://www.ruby-forum.com/.