tweet = Tweet.find(params[:id]) if tweet.user == current_user flash[:notice] = "Sorry, you can't retweet your own tweets" elsif tweet.retweets.where(:user_id => current_user.id).present? flash[:notice] = "You already retweeted!" else t = Tweet.new t.status = "RT #{tweet.user.name}: #{tweet.status}" t.original_tweet = tweet t.user = current_user t.save flash[:notice] = "Succesfully retweeted" end redirect_to tweet end end Quantas condições? Na action? class TweetsController < ApplicationController def retweet tweet = Tweet.find(params[:id]) if tweet.user == current_user flash[:notice] = "Sorry, you can't retweet your own tweets" elsif tweet.retweets.where(:user_id => current_user.id).present? flash[:notice] = "You already retweeted!" else t = Tweet.new t.status = "RT #{tweet.user.name}: #{tweet.status}" t.original_tweet = tweet t.user = current_user t.save flash[:notice] = "Succesfully retweeted" end redirect_to tweet end end class TweetsController < ApplicationController def retweet tweet = Tweet.find(params[:id]) if tweet.user == current_user flash[:notice] = "Sorry, you can't retweet your own tweets" elsif tweet.retweets.where(:user_id => current_user.id).present? flash[:notice] = "You already retweeted!" else t = Tweet.new t.status = "RT #{tweet.user.name}: #{tweet.status}" t.original_tweet = tweet t.user = current_user t.save flash[:notice] = "Succesfully retweeted" end redirect_to tweet end end segunda-feira, 17 de junho de 13