Created
April 21, 2009 04:16
-
-
Save sintaxi/98930 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Hit < ActiveRecord::Base | |
belongs_to :user | |
belongs_to :shot, :counter_cash => true | |
validate_on_create :check_for_gaming | |
def request=(request) | |
self.user_ip = request.remote_ip | |
self.user_agent = request.env['HTTP_USER_AGENT'] | |
end | |
private | |
def check_for_gaming | |
# smart method that checks for shit | |
end | |
end |
This file contains hidden or 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 Hits < Application | |
# this is a nested resource with only a create method | |
# we use render_then_call (merb only) just to pass back | |
# a 200 status before doing the calculation | |
# this action is hit with a XHR POST that looks like... | |
# http://example.com/shot/4587/hit | |
# | |
def create | |
only_provides :js | |
# returns a 200 and moves on. (if rails omit the render) | |
Merb.render_then_call(:status => 200) do | |
@shot = @shot.find(params[:shot_id]) | |
@hit = Hit.new(:shot => @shot, :user_id => current_user) #will pass in nil if user is not logged in | |
@hit.request = request | |
@hit.save | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment