- What are some ways in which HTML5 is different than older versions of HTML? Ans:
- Uses the simpler document header <!DOCTYPE html>.
- Has more meaningful content tags that can replace the div tag:
<article> <section> <header> <aside> <nav>
- The <canvas> tag allows JavaScript to draw graphical
pictures.
- Depreciated elements dropped: <center> <font>
<strike>.
- Explain the difference between a view and an action.
Ans: A view is an .html.erb file that contains HTML and ERB code. An action is a controller
method that executes on behalf of a view. The view is displayed immediately after the
action executes.
- Give some examples of how to be DRY in Rails. Ans: DRY means don't repeat yourself.
- Can use CSS code to apply to multiple views.
- A layout page can contain multiple views.
- A partial can be rendered by multiple views.
- Ruby code that used by multiple controllers can be placed in
application.html.erb.
- Methods that are called by multiple actions can be placed in the private section
at the bottom and called by before_action.
- What does CoC mean?
Ans: Convention over configuration. This means that if you
accept Rails conventions on where to put everything in the project
files, you shouldn't have to do any configuration.
- What does ERB mean?
Ans:
Embedded Ruby, which is Ruby code placed within ERB delimiters
<%= ... %> or <% ... %>.
- How much logic should you put in your ERB files?
Ans: As little as possible. Put most of your logic in the controller methods.
- List some Rails scaffold datatypes?
Ans: string, text, integer, float, boolean, date, datetime
- Give the hex color codes for these standard HTML colors:
aqua black blue fuschia gray green lime maroon
navy olive purple red silver teal yellow white
Ans: Look at this color wheel.
- What is the difference between an instance variable and a local variable.
Ans: A local variable is only valid within the method that it is used; an
instance variable is value anywhere in the class where it is used. For a Rails
project, an instance variable is value anywhere in the controller class.
- How can regular expressions be used to validate form input?
Example: validates :phone, with: { format:
/\A\d{3}\/\d{3}-\d{4}/ }
- What is a cryptographic hash?
Ans: It is a one-way encryption algorithm that can be used to encrypt passworks.
An example of such an algorithm is MD5. Another name for a cryptographic hash is a digest.
- What is the meaning of each of these symbols in Ruby and/or Rails?
+ - * < & ! . $
+ addition, string concatenation, array concatenation,
+= assignment operator
- subtraction, array difference, -=
assignment operator
* multiplication, string repetition, *=
assignment operator, /* ...
*/ CSS comment
< less than, <= less than or equal,
<< array append,
<!-- HTML comment, <=> spaceship operator
& bitwise and,
&& logical and, &= assignment operator,
< HTML special symbol
!
not, != not equal, <!-- HTML comment
. member selection operator, ..
inclusive range, ... exclusive range
$ jQuery selector, Ruby prefix for global variable
- Find the errors:
<% if Kid.first.gender = 'F' %>
<% @f %>
<% else if Kid.first.gender = 'M' =%>
<% @f %>
end
--- Corrected Version --------------------
<% if Kid.first.gender == 'F' %>
<%= @f %>
<% elsif Kid.first.gender == 'M' %>
<%= @m %>
<% end %>
- What is a migration?
Ans: It is a specification for creating or modifying a database table. Migration files
are stored in db/migrations. To run all pending migrations, use
rake db:migrate
- How can you correct errors in a migration before running rake db:migrate?
Ans: Edit the migration file.
- True or False: all Ruby methods are public.
Ans: In general, yes. However, the initialize method is always private. Also methods can be declared to
be private with the private keyword. See the bottom of a scaffold-based controller.
- How are JavaScript and jQuery related?
Ans: jQuery is a JavaScript library. It is based on selectors, for example
$("p"), $("#btn"),
$(".top").
- How are jQuery and CoffeeScript related?
Ans: CoffeeScript is a less wordy
version of jQuery, inspired by Ruby, Python, and Haskell. CoffeeScript uses
-> to define a function and uses indentation to indicate
the body of a function rather than curley braces.
- Name 5 methods from the Time class.
Ans: now year mon day hour min sec dst
- Name 5 methods from the Array class.
Ans: length empty? sort insert << [ ]
- Name 3 methods from the Range class.
Ans: begin end include?
- What is WEBrick?
Ans: It is the web server that ships with Ruby on Rails. It has a reputation
of being slow.
- In a Rails scaffold-based project, where do you put the CSS statements?
Ans: In the .scss files located in app/assets/stylesheets.
- How does Rails know which layout page to use for a specific view?
Ans: Rails looks for a layout page in app/views/layouts named
controller_name.html.erb
(replace controller_name by the name of the controller to which the view belongs). If no such file exists,
use the layout page application.html.erb.
- What is a partial?
Ans: It is a
piece of HTML and ERB that can be embedded into a view with the
render method. The filename of a partial starts with the
_ prefix.
- What is AJAX. For what is it used?
Ans: AJAX means Asynchronout JavaScript and XML. It is a set of technologies that allow
for partial page refreshes.
- How can you retrieve all of the rows in a database table?
Ans: ModelName.all, where you replace ModelName by the actual name of the ActiveRecord model.
- How can you obtain all rows where the salary field is greater than 90000?
Ans: ModelName.where("salary > 90000").all
- How do the HTTP verbs GET, POST, PUT, and DELETE map to the CRUD operations?
Ans: GET --> Read, POST --> Create, PUT --> Update, DELETE --> Destroy.
- Name seven ways of running Ruby code?
- IRB
- Ruby batch file
- ERB page
- Controller
- Ruby Console
- Load script into Ruby console
- Seed file
- What is the difference between form_tag and
form_for for defining a form?
Ans: In a form_tag form, the control helper methods end in
_tag. For FormTagHelper controls, the value from each control
must be obtained individually by the controller code using a params statement. With FormHelper methods,
a single record of information is obtained by the server, which can be inserted directly into the
database.
- Where do you put validations?
Ans: In the model files.
- What are some common validation options for the validates
method?
Ans: :format :inclusion :length :numericality :presence
- If there is more than one validation error, when attempting to insert
a new row into a database, what does Rails do?
Ans: It shows all of the validation errors.
- How do you specify a many-to-many relationship?
Ans: You put a belongs_to method call in the secondary model and a
has_many method call in the primary model.
- What does the Array method collect do?
Ans: It
collects together each piece of information returned by the code block and
assembles all these pieces into an array. Example:
a = [2, 3, 4, 5, 6]
b = a.collect do |n|
n ** 2
end
# Now the value of b is [4, 9, 16, 25, 36]
- What does before_action do?
Ans: It executes a
(usually private) method before executing an action.
- What is the session object?
Ans: A Ruby Hash object that stores information by key. This information is stored
for the entire user session (until all browsers are closed).
- How do you store information in a session object?
session[:key] = "piece of data"