Controller
View
Action
Port
Resource
Server
Layout
Scaffold
Method
Instance variable
Local variable
Control structure
Operator
Class
Object
Upper camel casing
Underscore notation
Ans: See the class notes or textbook.
Define these acronyms:
CoC
CSS
DRY
ERB
IRB
OSI
REST
ROR
UML
URL
XHTML
Ans: See the class notes, textbook, or an online search engine.
Name some server side scripting languages.
Ans: Ruby on Rails, PHP, ASP.Net, Django with Python, ColdFusion.
What are five ways to execute a Ruby script?
Ans: (a) Interactive Ruby, (b) a Ruby batch file, (c) from the
controller in a Rails project, (d) interactively from the Rails console,
(5) by loading a Ruby file from the Rails console.
What is the difference between a layout and a view?
Ans: When the layout and view are separated, the view is everything
between the <body> tags, the layout is everything else that is
common to all views. The yield :layout statement is used to insert the
view in the layout.
How do you pass data from the controller to a view?
Ans: Place a controller instance variable in the ERB code for the view.
Don't forget to place the instance variable in ERB delimiters.
How do you pass data from the controller to a layout?
Ans: The same way you pass data to a view as explained in the previous
problem.
Give examples of some Ruby objects used in Rails.
Ans: The controller classes in /apps/controllers are important
examples. Also, the scaffold software creates classes that correspond
to the resource that is being processed.
Write a Ruby statement to set item_id to a random integer
between 1,000 and 2,000, inclusive.
Ans: item_id = 1000 + rand(1001)
Write controller code that randomly assigns to @img one of the
images 1.jpg, 2.jpg, or 3.jpg. Suppose you want to place the image
on the page called index. Ans:
def index
i = 1 + rand(3)
@img = i.to_s + ".jpg"
end