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 <strong>
+1</strong>"

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)
   "<span style='color:green;' >#{agree_count -1} <strong>+
1</strong></span>
   &ndash;
   <span style='color:red;'>#{disagree_count}</span>"
end

def consensus_disagree(agree_count, disagree_count)
   "<span class='agree'>#{agree_count}</span>
   &ndash;
   <span class='disagree'>#{disagree_count -1} <strong>+
1</strong></span>"
end
-- 
Posted via http://www.ruby-forum.com/.