Last active
August 29, 2015 14:24
-
-
Save norbajunior/e52cf73379ecfa74d40b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def update | |
if @concert.update(params[:concert]) | |
@concert.confirm! | |
redirect_to user_concert_path(current_user, @concert), notice: t('flash.concerts.update_success') | |
else | |
@top_tippers = ConcertPayment.top_tippers(@concert).limit(5) # isso daqui dá pra melhorar, chamar @concert.top_tippers é mais legível | |
@concert_payments = @concert.concert_payments # se não for usar na view, nao precisa ser variavel de instancia esse @concert_payments | |
@amount = @concert_payments.amount # => faz scope disso map(&:amount).sum, sem usar os métodos do ruby. Faça um sql. | |
# faz um scope sql ao invés disso => select{|concert_payment| concert_payment.tip == false}.length | |
@audience = @concert_payments.audience.size # => scope :audience, -> { where(tip: false) } | |
flash[:alert] = t('flash.concerts.error_updating') | |
render :show_own | |
end | |
end | |
class Concert < ActiveRecord::Base | |
def streaming_time | |
time = duration + 20 | |
if started? | |
time -= ((Time.current - starts_at)/60).round | |
end | |
return (time < 0) ? 0 : time | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment