rails new app-name --skip-test-unit
- Better get the Gemfile looking spiffy/installed
- Don't forget to get all set up for PostgreSQL
- Use RSpec:
rails generate rspec:install
- Sexify README
- Deploy!
- Add the un-minimized Bootstrap assets to
vendor/assets
- require bootstrap in
application.css.scss
andapplication.js
rails generate controller StaticPages home help --no-test-framework
- Make the root route and a dummy view to test Bootstrap
- Create a general application layout with HTML5 shim
- Install spark gem with
Gemfile
- Add environment loading to
spec/spec_helper.rb
require 'rubygems'
require 'spork'
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
end
end
Spork.each_run do
# This code will be run each time you run your specs.
end
- Configure
.rspec
to use spark
--colour
--drb
- Run spork in the background and enjoy faster RSpec!
- Call (for example)
rails generate model User name:string email:string
replaced with your data- Timestamp data is automatically added
rake db:migrate
- Set accessible attributes with
attr_accessible :name, :email
- Consider annotating with
bundle exec annotate
rails generate migration add_index_to_users_email
- Find the migration in
db/migrate
- Edit the migration
- Run
rake db:migrate
rails generate migration add_password_digest_to_users password_digest:string
- Parses
_to_users
- Creates new column called
password_digest
of typestring
- Controller method
- Route
- View
- Optionally: Helpers, style sheets
SampleApp::Application.routes.draw do
match '/about', to: 'static_pages#about'
end
Automatically creates the named routes:
about_path => '/about'
about_url => 'http://localhost:3000/about'
- Create a new model or migration
- Migrate the database with
rake db:migrate
You can fix mistakes with rake db:rollback
or rake db:migrate VERSION=0
(replace 0).
Can validate:
- presence
- length
- format
- uniqueness
For uniqueness, you must enforce at the database level as well due to double-submission and app-database concurrency issues. This is done with a unique database index.
- Add string
password_digest
field to user's database model (and migrate) - Add
:password
and:password_confirmation
to user'sattr_accessible
- Add validations to password
- Validate presence of
password_confirmation
manually - Call
has_secure_password
in user's model, which performs magic relatingpassword
,password_confirmation
, andpassword_digest
, and creates anauthenticate
method
- Create a new test file with
rails generate integration_test static_pages
- Run tests using the
rspec
command with optional files/folders
describe "Home page" do
it "should have the content 'Sample App'" do
visit '/static_pages/home'
page.should have_content('Sample App')
end
end
Use vigorously!
In a layout:
<%= yield(:symbol)
returns the result of<% provide(:symbol, 'Symbol info') %>
<%= yield %>
returns the rest of the view's body
HTTP Request | URI | Action | Named Route | Purpose |
---|---|---|---|---|
GET |
/users | index |
users_path |
page to list all users |
GET |
/users/1 | show |
user_path(user) |
page to show user |
GET |
/users/new | new |
new_user_path |
page to make a new user (signup) |
POST |
/users | create |
users_path |
create a new user |
GET |
/users/1/edit | edit |
edit_user_path(user) |
page to edit user with id 1 |
PUT |
/users/1 | update |
user_path(user) |
update user |
DELETE |
/users/1 | destroy |
user_path(user) |
delete user |
…
User.new(name: "Michael Hartl", email: "mhartl@example.com")
User.create(name: "A Nother", email: "another@example.org")
(Automatically saves)User.find(1)
User.find_by_email("mhartl@example.com")
User.first
User.all
foo.valid?
foo.reload
foo.save
foo.destroy
- Ruby
- RVM
- RubyGems
- Bundler
- Rails
- Git