Skip to content

Instantly share code, notes, and snippets.

View radar's full-sized avatar

Ryan Bigg radar

View GitHub Profile
class CommentsController < ApplicationController
def index
@commentable = Video.find(params[:video_id])
@comments = @commentable.comments
end
def new
@commentable = Video.find(params[:video_id])
@comment = @commentable.comments.new
end
@radar
radar / code.rb
Created March 6, 2013 18:02 — forked from iwada/code.rb
#course_helper
def coursenames(courseid)
@coursedept = Department.all(:include => :courses, :conditions => ["courses.id = ?",courseid])
@coursedept.map(&:name)
end
<% @course.each do |course| %>
<tr>
<td><%= course.code %></td>
<%= link_to path_helper_goes_here, :class => "decideBtn" do %>
<i class="icon-plus icon-white"></i>
Add
<% end %>
@radar
radar / pt.yml
Created February 19, 2013 03:22 — forked from anonymous/pt.yml
activerecord:
errors:
models:
user:
errors: &errors
blank: campo obrigatório
attributes:
name: *errors
email: *errors
@radar
radar / Friendship.rb
Last active December 12, 2015 12:48 — forked from anonymous/Friendship.rb
class Friendship < ActiveRecord::Base
attr_accessible :friend_id, :user_id, :status
belongs_to :user
belongs_to :friend, :class_name => 'User', :counter_cache => :friends_count
def self.request(user, friend)
unless user == friend or Friendship.where(:user_id => user, :friend_id => friend).exists?
transaction do
create({:user => user, :friend => friend, :status => 'pending'}, :without_protection => true)
create({:user => friend, :friend => user, :status => 'requested'}, :without_protection => true)
@radar
radar / gist:4720628
Last active December 12, 2015 05:18 — forked from Benjmin/gist:4720543
class Page < ActiveRecord::Base
belongs_to :book
attr_accessible :link, :summary, :title
before_save :set_title
scope :title, where("title is not null")
def set_title
self.title ||= URI.parse(link).host
end
end
class BackgroundJobChecker
def self.check
Resque::Plugins::Status::Hash.statuses.each do |job|
return !job.working?
end
end
end
<% @hospitals.each do |hospital| %>
<% hospital.hospital_bookings.each do |booking| %>
@radar
radar / signup_spec.rb
Created November 14, 2012 22:49 — forked from nathanjsharpe/signup_spec.rb
Rspec problem
describe 'on signup page' do
before { visit '/signup' }
context "with invalid information" do
# tests here work great
end
context 'with valid information' do
@radar
radar / scope.rb
Created October 24, 2012 08:01 — forked from DriesS/scope.rb
Name scope use self.id
class Discount < ActiveRecord::Base
def unused
self.orders.
where(:state => ['shipped', 'paid', 'completed', 'processing']).
where(:user_id => user.id).
count
end
end