Ruby on rails practice

Reference online book: https://www.railstutorial.org/book/beginning

Cloude IDE
 cloud9 (https://c9.io/)
support Ruby, RubyGems, Git
 text editor, a filesystem navigator, and a command-line terminal

install rails
http://installrails.com/

create rails app
rails new hello_app
here hello_app is rails app name

After creating ruby on rails application, use bundler to install and include gems required by application

Gemfile
gem 'sqlite3'
 install latest version of gem "sqlite3"

 gem 'uglifier', '>=1.3.0'
 install latest version of uglifer gem if its version greater than or equal to 1.3.0

 gem 'coffee-rails', '~> 4.0.0'
 install coffee-rails verson newer than 4.0.0 less than 4.0.1
 only minor change ex: not 4.1

run rails app
cd hello_app;
rails server

on cloude IDE
rails server -b $IP -p $PORT

access local rails app hello_app
http://localhost:3000/

mvc flow diagram


root  /
root route

routes.rb
root 'application#hello'

git vesion controller code repository hosting
cloude ide.c9 support git by default
git configuration for first time

git config -global user.name "Shaik Ikbhal Basha"
git config -global user.email "iqbalforall@gmail.com"
git config -global push.default matching
git config -global alias.co checkout

----
git init
git add -A
#adds all files in the current folder to git project

if delete files accidentally , not committed
you can restore it from current working tree as
git checkout -f

git remote add origin https://github.com/ikbhal/hello_app.git
git push -u origin master

hosting
shared hosts or virtual private servers running Phusion Passenger (a module for the Apache and Nginx16 web servers), full-service deployment companies such as Engine Yardand Rails Machine, and cloud deployment services such as Engine Yard CloudNinefold, andHeroku.

Heoroku
group :production do
  gem 'pg',             '0.17.1'
  gem 'rails_12factor', '0.0.2'

end
bundle install --without production

shortcuts
rails s -> rails server
rails g -> rails generate
rails c -> rails console
rake test -> rake
bundle -> bundle instlal

generate controller
rails g controller StaticPages some help
undo the creating controller
rails destory controller StaticPages

creating model
rails g model User name:string email:string
rails destory  model User

app/views/static_pages/home.html.erb

StaticPages#home
Find me in app/views/static_pages/home.html.erb
--------
test/controllers/static_pages_controller_test.rb
require 'test_helper'

class StaticPagesControllerTest < ActionController::TestCase
  test "should get some" do
    get :some
    assert_response :success
  end

  test "should get help" do
    get :help
    assert_response :success
  end

end

No comments:

Post a Comment