1670879794aed7c23742e5b1f759be94?s=60
Generate a Rails App using Bash Scripts
by tomgdow
Introduction
rootrails [-h] <model_name || table_name> [<search_string>]

This program sets the application root in a Ruby-on-Rails 'config/routes.rb' file.

    The first compulsory argument is the table or model name. If the Model name is
    given, it will be converted to lowercase and pluralized. <table_name> format is
    to be preferred.

    The second argument is the search string, which defaults to 'welcome#index'

    You will be given a chance to revise the input before any changes are made

      -h: get help

    REQUIREMENTS
       Execute from the root directory of the rails app

    EXAMPLE USAGE
      rootrails Product
      rootrails products
      rootrails commodities 'products#index'

    NOTE
       Pluralization is not very clever. An 's' is added to a word that does not
       end in 's'.  'Product' is converted to 'products'
END
Generation of Rails App (Script Code)
uname -ro; rails -v; ruby -v; psql --version   # Preliminaries
railspg -c new myrailsapp 
psql -d postgres  -c 'SELECT datname, datallowconn  from pg_database' | grep 'myrailsapp*'
cd myrailsapp
rootrails products  # change roots
pryrails            # add pry gem
scaffoldp           # generate a scaffold
rails c             # start rails console
load '../productseed.rb' 
Product.all
exit
rails s -d          # Start rails server as 'daemon'  
lynx localhost:3000 
Ctrl-c
rails db            # Connect to db from within Rails app
select Name, Description, Price, id from products;
\q
Asciinema of Script Code
Generate a new Rails project with railspg
config/database.yml (final)
default: &default
adapter: postgresql
encoding: unicode
pool: 5
timeout: 5000

development:
  <<: *default
  database: myrailsapp_development
  username: johndow
  password: <%= ENV['POSTGRES_PASSWORD'] %>
  host: localhost
  port: 5432

test:
  <<: *default
  database: myrailsapp_test
  username: johndow
  password: <%= ENV['POSTGRES_PASSWORD'] %>
  host: localhost
  port: 5432

production:
  <<: *default
  database: myrailsapp_production
  username: johndow
  password: <%= ENV['POSTGRES_PASSWORD'] %>
Seed database (productseed.rb)
p1 = Product.new(:name => "Television",
                  :description => 'Retro devise for looking at life',
                  :price => 100)                                                      

p2 = Product.new(:name => "Computer",
                 :description => 'A device used to access Facebook',
                 :price =>200)

p3 = Product.new(:name => "Rails", 
                 :description => 'Great with cocaine, even better with Ruby',
                 :price =>400)

p4 = Product.new(:name => "Ruby", 
                 :description => 'Language created by Matz',
                 :price =>1000) 

p1.save
p2.save
p3.save
p4.save
hello
2etmekf