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 QuotationsController < ApplicationController | |
def index | |
@params = QuotationsIndexParams.new(params) | |
(redirect_to request.referer || quotations_path, :error => "Bad Request", :status => 400 and return) unless @params.valid? | |
@quotations = Quotation.search(@params.search_params). | |
send(@params.scope, @params.scope_params). | |
sorted_by(@params.sort.to_sym). | |
page(params[:page]) | |
respond_to do |format| | |
format.html # index.html.erb |
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 FooController < ApplicationController | |
def index | |
search_params = (params[:quotation] || {}).select{|k,v| !v.blank?} | |
q = search_params.delete("user") | |
if q | |
q = "%#{q}%" | |
search_params[:intended_trip] = {:user => {:conditions => ['email ilike ? or first_name ilike ? or last_name ilike ? or mobile_number ilike ?', q, q, q, q]}} | |
end | |
if params[:all] | |
@quotations = Quotation.all(search_params) |
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
require 'forwardable' | |
class User | |
extend Forwardable | |
attr_accessor :view_delegate_class | |
def_delegators :view_delegate, :full_name | |
def initialize(first_name, last_name) | |
@first_name = first_name |
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 Quotation | |
include DataMapper::Resource | |
# ...snip... | |
property :quoted_kms, Float | |
property :quoted_per_km, Float | |
property :quoted_price, Float | |
property :start_date, Date, :required => true | |
property :end_date, Date, :required => true |
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 QuotationStatusPolicy | |
def initialize(quotation) | |
@quotation = quotation | |
end | |
# STATUSES | |
def unconfirmed? | |
[:mildly_interested, :negotiating].include?(quality) | |
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 QuotationWorkflow | |
def initialize(object) | |
@object = object | |
end | |
include Workflow | |
workflow do | |
state :created do |
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 Quotation | |
# ...snip... | |
# methods to be forwarded to the status policy class | |
def self.status_policy_methods | |
[:unconfirmed?, :expirable?, :approvable?, :rejectable?, :poolable?, :on_holdable?, :payable?, :callbackable?, :sendable?] | |
end | |
# methods to be forwarded to workflow class |
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
# following are extracts from the relevant classes and not real Ruby code. | |
class Foo | |
belongs_to :user | |
end | |
class User | |
has n, :foos | |
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 ActivityLog | |
include DataMapper::Resource | |
property :id, Serial | |
property :type, Discriminator | |
property :model_id, Integer | |
property :event, String |
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 FoosController < ActionController::Base | |
# ..snip .. | |
def create | |
@foo = Foo.new(params[:foo]) | |
@foo.save_with_log(current_user) | |
# ... | |
end | |