install ruby, rubygems, git (version control), and rails
rails new - create rails application directory structure with app/, app/assests, app/controllers etc.; executes bundle install command Gemfile - add gems to be used in the app; update gem file and execute bundle upd ate and bundle install git version control - same like perforce; init, commit, branch, merge, push comm ands MVC model - Browser requests Rails Server, controller is invoked based on routi ng config, controller interacts with model which may use Database operations and finally controller renders a view. deploy - heroku - cloud deployment - create a space in cloud - push using git p ush heroku master Chapter 2 First step in Web Development - create a data model rake db:migrate to update db with our data models. Routing of URL.. config/routes.rb DemoApp::Application.routes.draw do resources :users . . . end Controller Actions (index, show, edit, new) the REST impl. and also (create, upd ate, destroy) to modify the database HTTP request URL GET /microposts microposts GET /microposts/1 ith id 1 GET /microposts/new ew micropost POST /microposts GET /microposts/1/edit ith id 1 PATCH /microposts/1 update DELETE /microposts/1 destroy
Action show new create edit
Associations and Vaildations(app/models/user.rb)
class User < ActiveRecord::Base has_many :microposts end class Micropost < ActiveRecord::Base belongs_to :user
Purpose index
page to list all
page to show micropost w page to make a n create a new micropost page to edit micropost w
update micropost with id 1
delete micropost with id 1
validates :content, length: { maximum: 140 }
end INHERITANCE Model classes inherits from ActiveRecord::Base , so that the model objects gain the ability to communicate with the database, treat the database columns as Ruby attributes, and so on. All controller classes inherits from ApplicationController, which itself inherit s from ActionController::Base; this is the base class for controllers provided b y the Rails library Action Pack. By inheriting ultimately from ActionController: :Base both the the controllers gain a large amount of functionality, such as the ability to manipulate model objects, filter inbound HTTP requests, and render v iews as HTML. CHAPTER 3 (Static Pages) Secure the token in config/initializers/secret_token.rb rails generate controller StaticPages home help --no-test-framework (config/routes.rb) SampleApp::Application.routes.draw do get "static_pages/home" get "static_pages/help" . . . end views => views/static_pages/help.html.erb Embedded Ruby for Do not repeat yourself principle Layout : app/views/layouts/application.html.erb <!DOCTYPE html> <html> <head> <title>Ruby on Rails Tutorial Sample App | <%= yield(:title) %></title> <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> <%= javascript_include_tag "application", "data-turbolinks-track" => true %> <%= csrf_meta_tags %> </head> <body> <%= yield %> </body> </html> Chapter 4 (Ruby) HELPERS app/helpers/application_helper.rb module ApplicationHelper # Returns the full title on a per-page basis. def full_title(page_title) base_title = "Ruby on Rails Tutorial Sample App" if page_title.empty? base_title else "#{base_title} | #{page_title}" end end end