Skip to content

Instantly share code, notes, and snippets.

module SessionsHelper
def sign_in(user)
cookies[:user_id] = user.id
@current_user = user
end
def signed_in?
! @current_user.nil?
end
module SessionsHelper
def sign_in(user)
cookies[:user_id] = user.id
@current_user = user
end
def signed_in?
! @current_user.nil?
end
@lessless
lessless / 01models.rb
Created September 27, 2012 20:51
has_many :through
class Meeting < ActiveRecord::Base
has_many :participations, dependent: :destroy
has_many :players, through: :participations
belongs_to :place
attr_accessible :place_id, :name
end
class Participation < ActiveRecord::Base
# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
# gem install pg
# On Mac OS X with macports:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
@lessless
lessless / gist:3854036
Created October 8, 2012 18:20
ajax_on_select.rb
=form_tag('/meetings/filter_by_city', remote: true) do
=select("place", "city",options_for_select(@places), {}, onchange: 'this.form.submit()')
class Place < ActiveRecord::Base
attr_accessible :address, :city, :name, :description
has_many :meetings
end
Class Meeting < ActiveRecord::Base
attr_accessible :start_at, :place_id, :title, :end_at
belongs_to :place
has_many :participations
CREATE TABLE places (
id integer NOT NULL,
address character varying(255) NOT NULL,
name character varying(255) NOT NULL,
city character varying(255) NOT NULL,
description character varying(255) NOT NULL,
);
CREATE TABLE meetings (
id integer NOT NULL,
validates :place_id, :title, :level, :start_at, :end_at, :presence => true
validates :start_at, :end_at, :inclusion => {
:in => DateTime.now.beginning_of_day..DateTime.now.end_of_month}
validates :place_id, :title, :level, :start_at, :end_at, :presence => true
validate :event_takes_place_in_one_day, :event_is_not_in_past
def event_takes_place_in_one_day
self.start_at.day == self.end_at.day
end
def event_is_not_in_past
admissible_range = DateTime.now.beginning_of_day..DateTime.now.end_of_month
admissible_range.cover?(self.start_at) && admissible_range.cover?(self.end_at)
end
@lessless
lessless / bank_spec.rb
Created October 30, 2012 11:20
route not found
#encoding:utf-8
require 'spec_helper'
describe Front::BanksController do
before :all do
@bank = Bank.create!(:name => 'ПУ БАНКА РОССИИ N 10462', :bic => '040009002')
end