Created
May 10, 2011 13:45
-
-
Save sauloarruda/964499 to your computer and use it in GitHub Desktop.
Modelagem de ontem
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 Participant < ActiveRecord::Base | |
has_many :points, :class => 'ParticipantPoints' | |
end | |
class ParticipantPoints < ActiveRecord::Base | |
attr_accessor :credit_debit | |
after_initialize :set_amount | |
after_create :update_current_points | |
def set_amount | |
self.amount = self.amount * -1 if @credit_debit == 1 | |
end | |
def update_current_points | |
self.participant.update_attribute(:current_points, self.participant.current_points + self.amount) | |
end | |
end | |
class ParticipantController < ApplicationController | |
# POST /participants/:id/update_points.json | |
def update_points | |
@participant.points.build(params[:points].merge(:manager => @current_manager)) | |
end | |
end | |
# _update_points.erb.html | |
<%= form_for @participant, @point do |f| %> | |
<%= f.text_field :amount %> | |
<%= f.radio_button :credit_debit, :value => 0 %> Credit | |
<%= f.radio_button :credit_debit, :value => 1 %> Debit | |
<%= f.text_area :description %> | |
<% end %> | |
@participant.current_points | |
# RootController | |
class RootController < ActionController | |
def index | |
domain = request.host | |
campaing = Campaing.actives.where(:custom_domain => domain).first | |
if campaing | |
redirect_to("/#{campaing.slug}") | |
else | |
render :invalid_campaign | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment