3. • Install Rails and all requirements from
http://railsinstaller.org/en
• Create an account at http://github.com
4. • Windows users, install Ruby 1.9+
• Mac users, you also get RVM. I’ll mention
that later.
• Sorry Linux, no Rails installer for you.
Google should help you here.
• I will continue to point out differences
between operating Systems.
19. Click ‘Add SSH key’.
For name, chose an
appropriate name for
your key. Mine is Benji-
mac.
20. right click paste. The
previous command
(clip < ~/.ssh/id_rsa.pub)
added the key to your
clipboard.
added the key to your
clipboard.
added the key to your
21. Click ‘Add key’. You
should also receive an
email telling you a key
has been added.
31. Click ‘Add SSH key’.
For name, chose an
appropriate name for
your key. Mine is Benji-
mac.
32. right click paste. The
previous command
(clip < ~/.ssh/id_rsa.pub)
added the key to your
clipboard.
added the key to your
clipboard.
added the key to your
33. Click ‘Add key’. You
should also receive an
email telling you a key
has been added.
34. Create a new folder for
your work
• And put it somewhere nice. I tend to go for
[username]/rails
35. Navigate there
• In terminal, type
cd ~/rails
• The ~ (tilde character) in this represents
your home directory.
36. Optional
• RVM stands for RailsVersion Manager. It’s
very useful if you’re using various versions
of Ruby, such as MacRuby or JRuby.
• Create a gemset using
rvm create gemset my-gems
• Then use this gemset with
rvm 1.9@my-gemset
38. • You have been asked to create an online
management system for a pet shop,“Jones’
Pets”.
• The system must, for now, keep track of
what pets are in stock, and how many of
each there are.
• The system will then be updated to handle
employee logins, and include a leaderboard
of who has sold the most animals.
42. • This will create a new folder in your rails
folder, called ‘pet-shop’
• Inside this folder, rails will have generated
everything you need to get started.
• Navigate into this folder using cd
pet_shop
52. • This is where you will find all the resources for
the app.
• This includes:
• CSS
• Javascript
• & images
• Don’t worry about what each of these do, for
now. I’ll get to them soon enough.
54. • A Rails controller interprets a request from
the browser, and then tells the application
what to do.
• eg., if you visit
http://twitter.com/BenjaminBoxler,Twitter
probably uses a controller routing my
username to a ‘show’ action in order to
display my timeline.
• Fun fact:Twitter was originally built in Ruby
on Rails, and parts of it reman so.
56. • This contains the code that bridges the
controller and the view.These can be
written directly in the view, but helpers
keep things clean and tidy.
• helpers in app/helpers/application_helper.rb
can be called from any view.
64. • This contains the templates from the
templates from which pages are loaded
into.
• application.html.erb is the default.
• .erb stands for ‘embedded Ruby’, and means
that Ruby can be called directly from that
page.
68. • This contains pages with no dynamic or
generated content.
• If your website contains a lot of static
pages, it is unlikely you would use this.
• We will briefly use this in our project.
70. • This file contains information about your
project. It’s not really needed, but because
we are going to useGitHub, we shall keep it
in.
• Don’t worry about the extension ‘rdoc’. It
stands for Ruby DOCumentation.We will
change it to ‘md’ to use Markdown.
74. What is Git?
• Git is a distributed version control system, used
for tracking changes to code to allow roll-backs
and security against corruption.
• Created in 2005 for version management of the
Linux kernal, by Linus Torvalds, founder of Linux.
• Created to make it near impossible for data loss to
occur over a distributed network.
• For an in-depth look at every aspect of Git, I
reccomend reading Pro-Git, available free online.
75. • Firstly, open an internet browser, and go to
http://github.com
• You should have created an account at the
beginning of this tutorial, so if you have, log
in (if you aren’t already), and if not, create
an account now.
78. • Create a new repository
(repo) using the third icon on
the right at the top-right of
the page.
• It looks like a book with a +
on it.
79. • For the name, I suggest
pet_shop, or
something equally
memorable and relevant.
• You may, optionally, add a
relevant description.
• Click create.
82. • You can do this in Terminal or CMD by
navigating to your project folder, if you’re
not already there, use
cd C:railspet_shop in Windows,
and cd ~/rails/pet_shop on mac.
83. • Then type git init to initialise the local
repository.
84.
85. But Git still thinks the
repository is empty,
despite having files
there.
86. • Let’s fix that.
• In terminal, now run git add .
(Don’t forget that trailing full stop!)
• It may look like nothing has happened, but
unless you get an error, it has probably
worked.
88. • All committing does, is tells your repository
that the files you listed in the last step have
changed, and you wish for it to take note of
it.
• In the last step, we didn’t list all the files in
the repository, because that would be silly.
We used the shorthand,‘.’ (Full stop)
89. • To commit your changes, you must run
git commit -m “initial
commit”
• The -m tells the command that the name
of the commit follows. In this case, the
name is “Initial commit”.
92. Okay, it’s not meant to
work yet. We haven’t
told our computer
where to push it.
93.
94. If you still have Github
open, you should see it
has given you some
code.
95. If you do not still have
Github open, please
return there, and once
logged in, select the
repository we created
earlier, from the list on
the right.
96.
97. We’re only interested
in the two lines
following, “Push an
existing repository
from the command
line”.
99. Note, you need to
change [username] to
whatever your Github
username is.
100. If you have named your
repository something
other than pet_shop,
you will also need ot
change that in the
command.
101. The first command
adds a new remote
repository to the
working directory, and
names it ‘origin’.
102. The second command
sets the default push to
that remote repository.
The -u flag sets the
upstream to a remote
named ‘origin’, on the
branch ‘master’.
103. Now lets have a look at
our project on Github.
(http://github.com/[username]/pet_store)
)
104. If it has all worked
properly, you should
see your list of files,
with a long, unrelated
README at the
bottom.
111. to open with TextMate, or
edit README.md
to open with
TextWrangler.
to open with
TextWrangler.
to open with
TextWrangler.
to open with
112. In Windows, you can add Notepad+
+ to your $PATH, but I’ll let Google
explain that one for you.
If this doesn’t take your fancy, you
can find the file in Explorer, and
right-click > Open with Notepad++
If this doesn’t take your fancy, you
can find the file in Explorer, and
right-click > Open with Notepad++
116. You can find more
information about the
formatting, here
http://daringfireball.net/projects/markdown/basics
http://daringfireball.net/projects/markdown/basics
118. Because you have already
alerted git of the new file
by using git mv, you
don’t need to use git
add . again. You can
just use
git commit -am “Updated README”
git commit -am “Updated README”
119. The new flag, -a, tells
git to just commit any
file that has been
changed, that has
already been marked by
git, using git add
130. Branching is the act of
diverging away from your
main Git record, for safety.
For example, I might want to
try something new, but if it
doesn’t work I don’t want it
to break the project, so I
would use a branch.
132. checkout changes branches,
whilst -b creates a new branch on
the fly. It’s important to note that
you can go between branches, and
edit them however, as long as you
commit between. You can then
merge the branches together, and
Git does a good job of doing this
automatically - you don’t need to
merge any files individually.
134. Controller. This is the name
for how the database and
webpage interact. It’s a little
more in depth than that, but I
will mention the basics as we
go through each part.
MVC stands for Model View
Controller. This is the name
for how the database and
webpage interact. It’s a little
135. rails generate resources Pets
animal:string price:integer
quantity:integer
(All one line.)
(All one line.)
136. Might take a minute, but you will see the output
on the console. Now would be a good time to
add and commit these files.
git add .
git commit -m “Generated pets controller.”
git commit -m “Generated pets controller.”
git commit -m “Generated pets controller.”
137. You can see the routes
created by running
rake routes from
the terminal.
139. [pet-shop(pets_controller)]$ rake routes
pets GET /pets(.:format) pets#index
POST /pets(.:format) pets#create
new_pet GET /pets/new(.:format) pets#new
edit_pet GET /pets/:id/edit(.:format) pets#edit
pet GET /pets/:id(.:format) pets#show
PUT /pets/:id(.:format) pets#update
DELETE /pets/:id(.:format) pets#destroy
140. If you don’t know what
this means yet, that’s
okay. You will find out
a bit more, shortly.
154. If you see that message,
it means your Ruby
server isn’t up and
running. Give it a
refresh and see if it
works.
155. You can have a click
around on this page, it
basically just tells you
about your Ruby
environment.
Not very useful. We’ll
get rid of it in a bit.
Not very useful. We’ll
156. But now you can head to
http://localhost:3000/pets
http://localhost:3000/pets