To Lecture Notes
IT 231 -- 9/13/12
Review Questions
- How do you open a Command Prompt Window?
Ans: Start >> All Programs >> Accessories >> Command Prompt.
You can also enter Start and type cmd in the box "Search programs and files."
- What are the Command Prompt DOS commands that do the following?
- Delete a file Ans: del
- Create a new folder. Ans: mkdir
- List all files in a folder. Ans: dir
- Move to the parent folder. Ans: cd ..
- Move to a child folder. Ans: cd foldername
- Move to the root folder on the current drive. Ans: cd \
- Change to a different drive. Ans: e: if you want to change to
drive e.
- Show the contents of a file on the screen.
Ans: type filename
- List the steps for creating and viewing a Rails project.
Ans:
- Use the rails command to generate the Rails scripts.
- cd into the newly created Rails project folder.
- Use rails generate controller to create the controller
and views.
- Start the server with rails server.
- View the project on localhost:3000.
- List some of the folders created for a Rails project.
Ans: Folders that we have used so far are app/controllers, app/views,
app/assets/images, app/assets/stylesheets. Here is a list of
Rails folders.
- What are views? Where are they located?
Ans: Views are HTML pages that are generated by Rails. A view is created
by combining an .html.erb Rails view with a layout to produce the generated
page.
- What is the difference between a view and a layout in Ruby on Rails?
Ans: The view is the content of the page that is normally between
the body tags. The layout is everything else on the HTML page.
- Where are images and CSS stylesheets placed in a Rails project?
Ans: In app/assets/images and app/assets/stylesheets, respectively.
- What is the file extension for view files?
Ans: .html.erb, where erb means Embedded Ruby.
- What is WEBrick?
Ans: A localhost server for Rails.
- What is one of the disadvantages of WEBrick?
Ans: It is slow. Its source code is also completely undocumented, which
gives it a bad reputation for some developers.
- What is a method in object oriented programming?
Ans: It is code that can be called by an object.
Methods are also called functions, subroutines, or procedures.
The Anatomy of a Rails URL
http is the protocol
localhost is the server name
3000 is the port number
photos is the controller
pets is the action
An action usually means execute a controller method and then
show the corresponding view.
If the Rails project were posted on an internet server,
localhost:3000 would be replaced by the internet address of
the server, for example, www.depaul.edu. The Rails URL would then be:
http://www.depaul.edu/photos/pets
To be able to display a view corresponding to an action, this route
must be set up in the config/routes.rb file. To display the view
associated with controller=photos; action=pets, this route is needed:
get 'photos/pets'
An id will be used later when we are displaying
information from databases.
For example
http://localhost:3000/photos/pets/23
displays the photo with id=23.
Embedded Ruby and Some Helper Functions
Place the image in the app/assets/images folder.
Look at Example 5 (PageWithImage).
Use this ERB helper function call to
to apply a CSS stylesheet to a web page:
<%= stylesheet_link_tag 'styles' %>
Place the stylesheet in the app/assets/stylesheets folder.
Use this ERB helper function call to
to create a hyperlink tag:
<%= link_to 'To Page 1', info_page1_path %>
"To Page 1" is the hyperlink text.
info_page1_page is a Rails helper function that indicates
the destination controller as into and the action
(destination view) as page1.
Examples
- Look at Examples 6 and 7.
Project 1
Submitting Projects
- To submit a Rails project:
Create a zip file by right clicking on the Rails folder
>> Send To >> Compressed (zipped folder)
- Submit your zipped project on
d2l.depaul.edu.