4. ‘DEBUGGING’ STUFF
WITHOUT DOCS
export BUNDLER_EDITOR=subl
bundle open rails
use Sublime Find in files
Tudi varianta:
git clone ....
Gemfile:
gem :devise, path:‘/home/user/stuff/devise’
Monday, June 10, 13
6. MEMOIZATIONTRICKS
def data
@data ||= begin
data = fetch_data("http://www.com")
JSON.load(data)
rescue Errno::ECONNREFUSED
{ error: 'Connection refused.' }
end
end
###
def data
@data = get_data unless instance_variable_defined?(:@data)
end
def get_data
# ...
rescue
# ...
end
Monday, June 10, 13
7. rails g model Fart ass:references
rails g model Fart ass:belongs_to
automatically adds index
automatically puts belongs_to into model
class CreateFarts < ActiveRecord::Migration
def change
create_table :farts do |t|
t.references :ass, index: true
t.belongs_to :ass, index: true
t.timestamps
end
end
end
class Fart < ActiveRecord::Base
belongs_to :ass
end
Monday, June 10, 13
9. PRESENT?
def show
@user = User.find(params[:id])
if @user.present?
# ...
end
end
def show
@user = User.find(params[:id])
if @user
# ...
end
end
STOP ABUSING!
Monday, June 10, 13