Created
February 10, 2010 17:31
-
-
Save workmad3/300591 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
class Request < ActiveRecord::Base | |
before_save :reduce_users_karma | |
validate :validate_karma | |
def validate_karma | |
if user | |
errors.add(:karma, "You don't have enough karma") unless user.karma_current > karma | |
else | |
errors.add(:user, "No user in request") | |
end | |
end | |
def reduce_users_karma | |
user.karma -= karma | |
user.save | |
end | |
end |
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 | |
@req = Request.new(params[:request]) | |
if @req.save | |
flash[:notice] = "Request created!" | |
redirect_to requests_path | |
else | |
flash[:error] = "We couldn't create your request, sorry." | |
render :action => 'new' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment