Professional Documents
Culture Documents
Ruby On Rails Yoi
Ruby On Rails Yoi
end
end
root 'pages#home'
The reference to the root path within the application code would be
root_path
Git references:
git-scm.com
git-scm.com/book/en/v2
gitref.org
First time (required only once to configure git for your environment):
replace Your name and Your email above with your actual name and email
address which you want shown on repo
git init
Note: if using Rails 5, your application will already come with a git
repository initiated, if you initiate a new one, it'll simply do the same step
again
git add -A
To check current state of file updates with already committed code in repo -
>
git status
git checkout -f
github.com
bitbucket.org
Production Deploy - Text
directions, references and code
Prepartion for heroku deploy:
group :production do
gem 'rails_12factor'
end
group :production do
end
- Save Gemfile
git add -A
Check heroku:
heroku -v
heroku version
heroku login
To add your SSH key to your heroku account so you don't have to use
username and password everytime ->
heroku keys:add
heroku create
Ensure you have committed all your local changes to your git repo
prior to pushing to heroku by checking git status
replace newnameofyourapp above with the name you'd like to give your
app
Your app will then be accessible from the following browser URL ->
newnameofyourapp.herokuapp.com
CRUD and Scaffold - Text
directions, references and code
Query language to communicate with database: SQL (Structured Query
Language)
CRUD actions:
C - Create
R - Read
U - Update
D - Delete
rake routes
The line resources :articles in the config/routes.rb file provides the following
routes:
- new article
- create article
- edit article
- delete article
- new article deals with the form to enter in new article details
- create handles the submission of the items in the new article form
- edit article deals with the form to enter in edit details for an existing article
To add attributes for the table in the migration file, add the following inside
create_table block:
t.string :title
t.text :description
t.timestamps
rake db:migrate
OR
rake db:rollback
In the above two adding column methods, the first argument is the name of
the table, second is the attribute name and third is the type
end
end
rails console
Article.all # classname.all will list all the articles in the articles table
article.save
OR
article = Article.new
article.save
article.save
article = Article.find(5)
article.destroy
To add validations presence and length validations to article model for title
and description:
end
If using Rails 5, the first line above would be -> class Article <
ApplicationRecord
To find errors in article object while saving (if it's rolled back):
article.errors.any?
article.errors.full_messages
Create New Articles from UI - Text
directions and code
In the config/routes.rb file add the following line to add all the routes for
articles:
resources :articles
def new
@article = Article.new
end
end
To create a view, under app/views create a folder named articles and within
it create a file named new.html.erb then fill in the following:
<h1>Create an article</h1>
<p>
</p>
<p>
</p>
<p>
</p>
def create
@article = Article.new(article_params)
@article.save
redirect_to article_path(@article)
end
private
def article_params
params.require(:article).permit(:title, :description)
end