Skip to content

Instantly share code, notes, and snippets.

@mathildathompson
Created March 17, 2014 03:49
Show Gist options
  • Select an option

  • Save mathildathompson/9593663 to your computer and use it in GitHub Desktop.

Select an option

Save mathildathompson/9593663 to your computer and use it in GitHub Desktop.
##RAILS
#The router works out which controller to talk to;
#The controller talks to the models, the models talk to the views;
#One file shows you all of the different routes in your programme;
##To get into you bash profile
subl ~/.bash_profile #Goes into your bash_terminal;
echo $PATH #Shows your path;
4.0.4
#Semantic versioning;
#The last digit
rails v #rails -v runs the rails programme;
rails new first_app -d postgresql #We are saying that we want to use the postgres database by default;
#Created a gem file and then run bundle install to install all of the gems;
rails generate scaffold movie title:string in_theatres:boolean release:date rating:string description:text
#Create a model, views and a controller;
database.yml
#Go to the development environment and change the usename to your usename;
#Add host: localhost and comment out the production and test configurations;
rake db:create
#To create the database;
rails server
#To start up the server, listens on port 3000;
#In browser go to localhost:3000
rake routes
#Shows all the routes in the application;
##Database
schema.rb #Showing the current state of our database;
development.log #Keeps track of everything that has happenned;
rails console #You can access the database from here;
#In routes.rb #pages is the controller and home is the action (a method inside of a controller is called an action);
Basics::Application.routes.draw do
root :to => 'pages#home' #Where the root of the application goes, you can only define this once in the routes file;
get '/home' => 'pages#home'
get '/about' => 'pages#about'
end
pages_controller.rb #create this file in the controllers folder, follow this convention or it will not be able to find it;
class PagesController < ApplicationController
def home
render 'comingsoon' #If you want to override the default which would be home.html.erb you can render the view you want to display;
end
def about
redirect_to('/butterflies') #
end
end
#In the view folder create a pages folder and in this create a home.html.erb (serving html here);
gem 'pry' in the Gemfile and then run bundle so it will re-bundle all our gems in the application;
gem 'pry-rails' #depends on pry, so authomatically installs pry for you;
gem 'pry-debugger'
gem 'pry-stack_explorer'
##IMAGES
#Images live in the assets/images folder #Present the image as being in 'assets/funny', but is actually in 'assets/images/funny' - it flattens out the folder structure;
##CSS
#Styles that you want all over the application you can put in application.css
gem 'better-errors'
gem 'binding_of_caller'
##ADMIN/SHORTCUTS
ruby -v #Shows the version of ruby that you are using
rails console #You can access the database from here when inside the application folder;
rake routes #To look at the routes;
cmd + p #will go and find the file in sublime;
#Get better errors to work with sublime text;
http://dwradcliffe.com/2013/01/18/better-errors-with-sublime-text.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment