text version ------------------------------------------------------ Best to view the text version of this file, as I don't feel like escaping html tags: ------------------------------------------------------ ruby -v Display ruby version installed rails -v Show rails version installed. mkdir /someplace/railsites && cd /someplace/railsites Create a directory for rails projects and change to that directory. rails new mySuperApp rails new ~/someplace/railsites/mySuperApp Creates a skeleton structure for new rails application. The first example would create it in the current folder. rails server rails s Start rails server (WEBrick). The second example is just a shorter version. Make sure you are in the new apps folder you just created. If you an execjs, could not find a javascript runtime error: Try installing: nodejs http://localhost:3000/ Take your browser here and make sure it is working. Create first test site. ----------------------- rails generate controller Pages home Generates a controller and some pages including one called home. You can create more pages by: rails generate controller Pages home about gallery But we can add them later also. http://localhost:3000/pages/home Now you can view the page called home. It will tell you where it's .erb location is. app/controllers/pages_controller.rb This also created a pages controller. config/routes.rb It also created a routes.rb This file maps urls to the files on disk. You can view it to see how the home page above is mapped with a get. We can set this as the default page by editing the routes.rb and commenting the 'get' line and adding a 'root' line that points to the home page that was created above. Only edit these lines and leave the rest alone. Edit routes.rb: --------------- #get 'pages/home' root 'pages#home' ------------------ end-edit-routes.rb http://localhost:3000/ Now going here will will be the pages/home file. Edit routes.rb again and add an about page. Now the lines that have changed in this file are: Edit config/routes.rb: ---------------------- #get 'pages/home' get 'about' => 'pages#about' root 'pages#home' ----------------- end-edit-routes.rb Now add an action to pages_controller.rb, using: def action end Edit: app/controllers/pages_controller.rb ----------------------------------------- class PagesController < ApplicationController def home end def action end end ----------------------- end-pages_controller.rb A view still need to be created for this about page. Edit views/pages/about.html.erb ------------------------------- Hi I am a rails master. This is my best page. All your internets belong to me, now. ------------------ end-about.html.erb http://localhost:3000/about Now go to about page and be what your read. To add or edit content that is on every page, like links, header, footer etc. Edit the application.html.erb file. Adding these lines in the appropriate place, the first two are the links, the last three are the footer.: <%= link_to "Home", root_path %> <%= link_to "About", about_path %> Edit: app/views/layouts/application.html.erb -------------------------------------------- My Rails Study Guide <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> <-- Links --> <%= link_to "Home", root_path %> <%= link_to "About", about_path %> <%= yield %> <-- Footer --> ------------------------ end-application.html.erb If the application page starts getting to cluttered, and your prefer the links and headers to be in seperate files. You could do this instead: Create a header page, _footer.html.erb: Edit: app/views/layouts/_footer.html.erb ---------------------------------------- <%= link_to "Home", root_path %> <%= link_to "About", about_path %> -------------------- end-_footer.html.erb Create a footer page, _header.html.erb: Edit: app/views/layouts/_header.html.erb ---------------------------------------- -------------------- end-_header.html.erb Now the applicatins.html.erb can be changed by adding two render lines: <%= render 'layouts/header' %> <%= render 'layouts/footer' %> Edit: app/views/layouts/application.html.erb -------------------------------------------- My Rails Study Guide <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> <%= render 'layouts/header' %> <%= yield %> <%= render 'layouts/footer' %> ------------------------ end-application.html.erb End-create first test site -------------------------- Create another site. Go back to the /someplace/railsites folder and create a new site that will be a picture gallery. Create gallery site ------------------- cd /someplace/railsites rails new gallery cd gallery rails server http://localhost:3000/ Make sure site is up and running in a browser. ---------------- end-gallery-site Books ----- Ruby on Rails Tutorial, Learn Rails by Example Beginning Ruby The Well-Grounded Rubyist Eloquent Ruby The Ruby Way Rails Resources --------------- RailsCasts Tealeaf Academy Code School Rails Guides Rails for Zombies IDEs ---- RadRails RubyMine