Getting started Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Explain what is the config/routes.rb file.

1. Hints routing file that does X

A
  • The Application’s routing file which holds entries in a special DSL (domain-specific language) that tells Rails how to connect incoming requests to controllers and actions.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Tell me about root ‘welcome#index’

1. Tells rails to map

A

root ‘welcome#index’ tells Rails to map requests to the root of the application to the welcome controller’s index action and get ‘welcome/index’ tells Rails to map requests to http://localhost:3000/welcome/index to the welcome controller’s index action.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain what is a new resource

2.CRUD

A

A resource is the term used for a collection of similar objects, such as articles, people or animals. You can create, read, update and destroy items for a resource and these operations are referred to as CRUD operations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain what going on in this Error message.Missing template articles/new, application/new with {locale:[:en], formats:[:html], handlers:[:erb, :builder, :coffee]}. Searched in: * “/path/to/blog/app/views”

  1. The first part identifies
A

The first part identifies what template is missing. In this case, it’s the articles/new template. Rails will first look for this template. If not found, then it will attempt to load a template called application/new. It looks for one here because the ArticlesController inherits from ApplicationController.

The next part of the message contains a hash. The :locale key in this hash simply indicates what spoken language template should be retrieved. By default, this is the English - or “en” - template. The next key, :formats specifies the format of template to be served in response. The default format is :html, and so Rails is looking for an HTML template. The final key, :handlers, is telling us what template handlers could be used to render our template. :erb is most commonly used for HTML templates, :builder is used for XML templates, and :coffee uses CoffeeScript to build JavaScript templates.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Explain how rails searches for this template.app/views/articles/new.html.erb.

  1. Template called “X”, within “X” Format and Handler
A

The extension of this file name is key: the first extension is the format of the template, and the second extension is the handler that will be used. Rails is attempting to find a template called articles/new within app/views for the application. The format for this template can only be html and the handler must be one of erb, builder or coffee. Because you want to create a new HTML form, you will be using the ERB language. Therefore the file should be called articles/new.html.erb and needs to be located inside the app/views directory of the application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain this code.

<p>
<br></br>

</p>

<p>
<br></br>

</p>

<p>

</p>

2.
Also Explain why you would make this edition

A

When you call form_for, you pass it an identifying object for this form. In this case, it’s the symbol :article. This tells the form_for helper what this form is for. Inside the block for this method, the FormBuilder object - represented by f - is used to build two labels and two text fields, one each for the title and text of an article. Finally, a call to submit on the f object will create a submit button for the form.

2.The form needs to use a different URL in order to go somewhere else. This can be done quite simply with the :url option of form_for. Typically in Rails, the action that is used for new form submissions like this is called “create”, and so the form should be pointed to that action.he articles_path helper tells Rails to point the form to the URI Pattern associated with the articles prefix; and the form will (by default) send a POST request to that route. This is associated with the create action of the current controller, the ArticlesController.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What happens when a form is submitted

1. The fields are

A

When a form is submitted, the fields of the form are sent to Rails as parameters. These parameters can then be referenced inside the controller actions, typically to perform a particular task.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Explain this.def create
render plain: params[:article].inspect
end

  1. The render method is
A

The render method here is taking a very simple hash with a key of plain and value of params[:article].inspect. The params method is the object which represents the parameters (or fields) coming in from the form. The params method returns an ActiveSupport::HashWithIndifferentAccess object, which allows you to access the keys of the hash using either strings or symbols. In this situation, the only parameters that matter are the ones from the form.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly