gem install rails -v 4.2.2
rails 4.2.2 new hello_app
/app /app/assets /bin /config /db /doc /lib /lib/assets /log /public /bin/rails /test /tmp /vendor /vendor/assets /README.rdoc /Rakefile /Gemfile /Gemfile.lock /config.ru /.gitignore
source 'https://rubygems.org'
gem 'rails', '4.2.2'
# the >= notation always installs the latest gem
# the ~> only installs updated gems representing minor point releases
group :development, :test do
gem 'spring'
end
bundle install
bundle install --without production
rails server -b $IP -p $PORT
gem install bundler
heroku login
heroku create
git push heroku master
heroku open
heroku log --tail
rails generate scaffold User name:string email:string
bundle exec rake db:migrate
bundle exec rake db:rollback
bundle exec rake -T db
rails console
Rails.application.routes.draw do
root 'application#hello'
resources :users
get 'static_pages/home'
end
rails generate controller {ControllerName} {action} {action}
app/controllers/*_controller.rb
class ApplicationController < ActionController::Base
def hello
render text: "hello, world!"
end
end
class UsersController < ApplicationController
def idnex
@users = User.all
# @ called instance variable
end
end
rails destroy controller {ControllerName} {action} {action}
rails generate model User name:string email:string
app/models/user.rb
class User < ActiveRecord::Base
end
class Micropost < ActiveRecord::Base
validates :content, length: { maximum: 140 }
end
claass User < ActiveRecord::Base
has_many :microposts
end
class Micropost < ActiveRecord::Base
belongs_to :user
end
class Micropost < ActiveRecord::base
belongs_to :user
validates :content, length: { maximum: 140 },
presence: true
end
rails destroy model User
app/views/users/index.html.erb
<%= %>
<%= link_to 'text', path %>
<%= provide(:title, "Home") %>
<%= yield(:title) %>
<%= render 'layouts/shim' %>
test/controllers/static_pages_controller_test.rb
require 'test_helper'
class StaticPagesControllerTest < ActionController::TestCase
test "should get home" do
get :home
assert_response :success
assert_select "title", "Home | Ruby on Rails Tutorial Sample App"
end
end
rails generate integration_test site_layout
require 'test_helper'
class SiteLayoutTest < ActionDispatch::IntegrationTest
test "layout link" do
get root_path
assert_template 'static_pages/home'
assert_select "a[href=?]", root_path, count: 2
end
end
require 'test_helper'
class UserTest < ActiveSupport::TestCase
def setup
@user = User.new(name: "Example User", email: "[email protected]")
end
test "should be valid" do
assert @user.valid?
end
end
bundle exec rake test