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 Transition | |
def self.sql_dump_import(dump_file) | |
sql = File.open(dump_file).read | |
sql.split(';').each do |sql_statement| | |
ActiveRecord::Base.connection.execute(sql_statement) unless sql_statement.blank? | |
end | |
return 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
#SomeController | |
def show | |
with_404 { Model.find(params[:id]) } | |
end | |
#ApplicationController |
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 Assignment < ActiveRecord::Base | |
# Relationships | |
belongs_to :user | |
belongs_to :project | |
# Scopes | |
scope :active, where('assignments.active = ?', true) | |
scope :inactive, where('assignments.active = ?', false) | |
scope :for_project, lambda { |project_id| where('project_id = ?', project_id) } | |
scope :for_user, lambda { |user_id| where('user_id = ?', user_id) } |
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
{ | |
"id": 7, | |
"tags": ["programming", "javascript"], | |
"users": [ | |
{"first": "Homer", "last": "Simpson"}, | |
[2, "Hank", "Hill", "Peter", "Griffin"] | |
], | |
"books": [ | |
{"title": "JavaScript", "author": "Flanagan", "year": 2006}, | |
[3, "Cascading Style Sheets", "Meyer", 2004] |
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 'open-uri' | |
File.open('/Users/jon-paullussier/sandbox/mypicture.jpg', 'wb') {|f| f << open("http://i.imgur.com/0JEgI.jpg").read} |
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 update | |
@project = Project.find(params[:id]) | |
@project.update_attributes!(params[:project]) | |
respond_to do |format| | |
format.html do | |
if request.xhr? | |
# *** repond with the new value *** | |
render :text => params[:project].values.first | |
else |
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
gist without user |
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
(rdb:1) self.margin_box | |
#<Prawn::Document::BoundingBox:0x10a0a17d8 | |
@y=756.0, | |
@total_left_padding=0, | |
@width=356.0, @x=36, | |
@stretched_height=nil, | |
@document=#<PrawnHelper::JennerPdf:0x10a0a2b10 # <<<< Notice this object DOES NOT end before the comma, #<CLASS::MODULE::OBJECT:ID (no closing >) | |
@y=756.0, | |
@bounding_box=#<Prawn::Document::BoundingBox:0x10a0a17d8 ...>, # <<<< Notice this object ends before the comma, #<CLASS::MODULE::OBJECT:ID ...> | |
@page_number=1, |
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 Model < ActiveRecord::Base | |
attr_accessor :an_array | |
WORDS = ['Some', 'Strings', 'In', 'Array'] | |
def an_array= | |
an_array = words | |
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 ApplicationController < ActionController::Base | |
protect_from_forgery | |
def is_a_help? | |
unless current_user.admin? | |
redirect_to :back, notice: 'Sorry.' | |
end | |
end | |
end |