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 State < ActiveRecord::Base | |
| def self.default | |
| find_by(default: true) | |
| end | |
| def make_default! | |
| PgLock.new(name: 'set_state_default').lock do | |
| State.update_all(default: false) | |
| update(default: true) | |
| 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
| # app/drops/invoice_drop.rb | |
| class InvoiceDrop < Liquid::Drop | |
| delegate :days_late, :priceinbtw, :print_date, :id, :late, :unpayed, to: :invoice | |
| attr_reader :invoice | |
| def initialize(invoice) | |
| @invoice = invoice | |
| 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
| def authenticate | |
| if params[:username].present? && params[:password].present? | |
| inn = Inn.find_by(username: params[:username]) | |
| if inn | |
| authenticated = inn.authenticate(params[:password]) | |
| if authenticated | |
| redirect_to inns_url, notice: 'You are now logged in.' | |
| return |
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
| resource :report do | |
| resources :subjects, only: :index | |
| 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
| Rails.application.routes.draw do | |
| resources :categories | |
| devise_for :admins | |
| devise_for :users | |
| resources :users | |
| namespace :admin do | |
| resources :categories | |
| 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
| if params[:friend_id] | |
| friend = User.find(params[:friend_id]) | |
| else | |
| # ... | |
| 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
| urls.each do |url| | |
| begin | |
| open(url) | |
| # do some nokogiri things | |
| rescue OpenURI::HTTPError | |
| # log the error | |
| 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 CreateGroupLocations < ActiveRecord::Migration | |
| def change | |
| create_table :group_locations do |t| | |
| t.belongs_to :address, index: true, foreign_key: true | |
| t.belongs_to :group, index: true, foreign_key: true | |
| t.timestamps null: false | |
| end | |
| 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 CreateCategories < ActiveRecord::Migration | |
| def change | |
| create_table :categories do |t| | |
| t.string :name | |
| t.timestamps | |
| end | |
| 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 NotePolicy < ApplicationPolicy | |
| # For index action | |
| class Scope | |
| attr_reader :user, :scope | |
| def initialize(user, scope) | |
| @user = user | |
| @scope = scope | |
| end |