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 FormObject | |
| include ActiveModel::Model | |
| def initialize(args={}) | |
| args.each do |k,v| | |
| instance_variable_set("@#{k}", v) unless v.nil? | |
| end | |
| end | |
| def save |
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
| #encoding: utf-8 | |
| class PolicyService < BaseService | |
| attr_accessor :policy_form | |
| def initialize(current_user, params, request) | |
| super | |
| @policy_form = PolicyForm.new(params[:policy].merge(current_user: @current_user, id: params[:id].present? ? params[:id] : nil)) | |
| end | |
| def process_create |
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 'spec_helper' | |
| describe TicketsController, type: :controller do | |
| it 'should confirm ticket' do | |
| body_of_test | |
| 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 AbstractModel < ActiveRecord::Base | |
| scope :for_agency, lambda { |user| | |
| where("agency_id = ?", user.agency_id) | |
| } | |
| end | |
| #some example models | |
| class Foo < AbstractModel | |
| end | |
| class Bar < AbstractModel |
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 Client < ActiveRecord::Base | |
| include CompanyScope | |
| end | |
| # and so on for each model |
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 ClientsController < CompanyScopedController | |
| before_filter :set_client, only: [:show, :edit, :update, :destroy] | |
| def index | |
| @clients = clients_scoped.paginate(per_page: 20, page: params[:page]) | |
| end | |
| private | |
| def set_client |
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 ApplicationPolicy | |
| # ... content generated by pundit (its about access for actions - we will discuss it in part 2 of that blogpost) | |
| class Scope # our default scope for each model | |
| attr_reader :user, :scope | |
| def initialize(user, scope) | |
| @user = user | |
| @scope = scope | |
| 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
| { 'KR' : 'Angular and stuff', 'AP' : 'Jasmine', 'AC' : 'AexolGl'} |
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
| {'XX' : 'YYY', 'ZZ': 'AAA'} |
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
| MyRequests.prototype.display_response = function(response){}; | |
| MyRequests.prototype.get_topics = function(bstokJS_stage) { | |
| $.ajax({ | |
| type: 'GET', | |
| url: 'https://gist.githubusercontent.com/panSarin/3d0e3080ee36e3b82c79/raw/8f496cfd22a766644b0ee834afb813ca1790c304/bstokjs'+bstokJS_stage+'.json', | |
| contentType: "application/json; charset=utf-8", |