Skip to content

Instantly share code, notes, and snippets.

#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)

true and false vs. "truthy" and "falsey" (or "falsy")

Update

Hi! I'm Jesse. I co-founded Dev Bootcamp in 2012 with Shereef Bishay and Dave Hoover, but left recently to work on a new project. If you're reading this, you're probably interested in learning how to program. I'm working on something new that might just be up your alley. Shoot me an email at jesse@20bits.com if you're interested.

Back to our regularly-scheduled programming

Many programming languages, including Ruby, have native boolean (true and false) data types. In Ruby they're called true and false. In Python, for example, they're written as True and False.

Exposing an API

APIs are becoming an essential feature of modern web applications. Rails does a good job of helping your application provide an API using the same MVC structure you're accustomed to.

In the Controller

Let's work with the following example controller:

class ArticlesController < ApplicationController
@elikem
elikem / web_safe_fonts
Created July 1, 2014 14:24
web safe fonts
font-family: Arial, Helvetica, sans-serif;
font-family: 'Arial Black', Gadget, sans-serif;
font-family: 'Bookman Old Style', serif;
font-family: 'Comic Sans MS', cursive;
font-family: Courier, monospace;
font-family: 'Courier New', Courier, monospace;
font-family: Garamond, serif;
font-family: Georgia, serif;
font-family: Impact, Charcoal, sans-serif;
font-family: 'Lucida Console', Monaco, monospace;
<%= render :partial => 'task', :collection => @tasks %>
<%= render :partial => @tasks %>
@elikem
elikem / active_record_and_migrations_single_file.rb
Last active August 29, 2015 14:03
active record and migrations single file
# Create a new database each time
File.delete 'dbfile' if File.exist? 'dbfile'
require 'active_record'
ActiveRecord::Base.establish_connection :adapter => "sqlite3",
:database => "dbfile"
# Initialize the database schema
ActiveRecord::Base.connection.create_table :ducks do |t|
t.string :name
@elikem
elikem / Rakefile
Created July 8, 2014 15:16
load your gem into irb with auto-completion
task :console do
require 'irb'
require 'irb/completion'
require 'my_gem' # You know what to do.
ARGV.clear
IRB.start
end
@elikem
elikem / ruby_method_with_predefined_format_argument.rb
Last active August 29, 2015 14:04
ruby method w/ predefined format argument
class Twitter
include HTTParty
def self.user_info(username, format = :json)
get "http://api.twitter.com/1/users/show/#{username}.#{format}"
end
end
#!/bin/sh
echo Install all AppStore Apps at first!
# no solution to automate AppStore installs
read -p "Press any key to continue... " -n1 -s
echo '\n'
# install wallpaper cli
sudo gem install desktop
echo Install Homebrew, Postgres, wget and cask
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
@elikem
elikem / .pryrc
Created July 30, 2014 11:33 — forked from bespokoid/.pryrc
# === EDITOR ===
Pry.editor = 'vim'
# == Pry-Nav - Using pry as a debugger ==
Pry.commands.alias_command 'c', 'continue' rescue nil
Pry.commands.alias_command 's', 'step' rescue nil
Pry.commands.alias_command 'n', 'next' rescue nil
Pry.commands.alias_command 'r!', 'reload!' rescue nil
Pry.config.color = true