Command and Phrase Cheat Sheet
|rails new||This command creates a new rails app.||rails new quick_blog|
|cd||Change Directory. This will open your application folder in the command line.||cd quick_blog|
|rails server or rails s (for short)||This will start the server so that you can view your application in your browser locally.||
Open localhost:3000 in your browser to view your app locally.
|Ctrl + c||This will stop the program that is running. You will use this to stop the Rails Server.||
To continue working on your application you will need to stop the Rails Server.
Once the Rails Server has been stopped you will no longer be able to view your application in your browser until it is run again.
|rails generate or rails g (for short)||This will generate templates of code that you need for your app to run. This saves you from having to write all of the code yourself.||
Rails generate scaffold (or any generator type).
When you type rails generate it will give you a list of generators you can use.
|rails g scaffold||This generates the code for all the things you need for a new resource. This includes models, views and controllers (MVC). It also creates the ability to do these basic actions: create a new resources, edit a resource, show a resource and delete a resource.||
rails g scaffold Post title body:text
‘Post title’ is the name of your scaffold, ‘body’ is the attribute and ‘text’ is the type (ie. string,integer…) of attribute that it is.
eg. You can now create new posts, edit posts, update posts and delete posts.
Rake is Ruby ‘Make’, a standalone Ruby utility.
It uses ‘Rakefile’ and .rake files to build up a list of tasks and is used for common administration tasks.
This command is used to apply your migration (eg. Creating a new scaffold) to your database (db).
Your database is updated overtime as you apply each migration. Eg. It started off with nothing in it, now it has a table with a title column and a body column.
The rake routes command will give you a list of all your defined routes. This can be used to find routing problems or give you an overview of the URLs in an app.
|bundle install or bundle (for short)||This command installs your new gems. When you add a new gem to your Gemfile you’ll need to run bundle install in your command line to install it.||
bundle install –without production
This means don’t install production gems such as postgres.
|Active Record||Active Record is the Model part of MVC.||
class CreatePosts < ActiveRecord::Migration
This migration creates your table.class Post < ActiveRecord::Base This will create a Post model, mapped to a posts (Rails will pluralize your class names to find the respective database table) table at the database.
A symbol is a name used to represent something in your app.
Symbols only keep one copy in memory (unlike strings), so they are generally used to save on memory in your application.
|attr_accessible||Attribute accessible allows you to access an attribute outside of the instance itself.||attr_accessible|
|<%= %>||This indicates that ruby code is to be evaluated within the HTML. It can do things such as add links.||<%= link_to 'Edit', edit_post_path(@post) %>|
|==||With two equal signs you can check if two things are the same. If so, true will be returned.||name == “admin”|
|&&||It is logical AND evaluates to true or false. If both are true then the condition becomes true.||name == “admin” && password == “secret”|
|@attributes||Attributes are specific properties of an object. They are instance variables of a class instance. Ruby stores the name in a @name instance variable||@posts|
|Method||Methods are capabilities of an object. A method is used to create parameterized, reusable code.||
create_table :posts do |t|
t.timestamps end end
|Class||A class allows you to create objects of a particular type and to create methods that relate to those objects.||
class Post < ActiveRecord::Base
attr_accessible :body, :title
validates :body, :title, presence: true
The “<" means one class inherits from another class.
|Version Control||Action||InstallFest Example|
|git init||This command create an empty Git repository.||git init|
|git add .||This command adds a change in the working directory to the staging area telling Git to include updates to a particular file in the next commit.||git add .|
This command takes the staged code that was added and commits it to the project repository.
This stores your code so that if you lose or change something locally, you have a way to retrieve a previous version.
git commit -m "initial blog commit”
- m is message related to that commit.