Created
January 26, 2015 18:43
-
-
Save aristotelesbr/aaf1a272be442b8bcd6e to your computer and use it in GitHub Desktop.
Criar uma nova venda somente se o valor em Produtos for maior que 0.
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 create | |
@sale = Sale.new(sale_params) | |
if @sale.amount <= @product.amount | |
redirect_to root_path, :notice => "Quantidade indisponível" | |
else | |
@sale.save | |
respond_with(@sale) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Não sei como está sua lógica de Models, eu faria algo parecido com isso, um before_save que checasse o sale.amount.