230 Matching Annotations
- Jul 2015
-
guides.rubyonrails.org guides.rubyonrails.org
-
every Rails model can be initialized with its respective attributes, which are automatically mapped to the respective database columns
-
command will apply to the database defined in the development section of your config/database.yml file
-
Migrations are Ruby classes that are designed to make it simple to create and modify database tables. Rails uses rake commands to run migrations, and it's possible to undo a migration after it's been applied to your database.
-
Rails responded by creating a bunch of files. For now, we're only interested in app/models/article.rb and db/migrate/20140120191729_create_articles.rb
-
a text attribute of type text.
-
a title attribute of type string
-
we want a Article model,
-
database tables use a plural name.
-
Models in Rails use a singular name
-
When a form is submitted, the fields of the form are sent to Rails as parameters.
-
This is associated with the create action of the current controller
-
the form will (by default) send a POST request
-
The articles_path helper tells Rails to point the form to the URI Pattern associated with the articles prefix
-
you will see that the action attribute for the form is pointing at /articles/new. This is a problem because this route goes to the very page that you're on right at the moment, and that route should only be used to display the form for a new article.
-
When you call form_for, you pass it an identifying object for this form.
-
handler must be one of erb, builder or coffee.
-
format for this template can only be html
-
second extension is the handler that will be used.
-
the first extension is the format of the template
-
app/views/articles/new.html.erb.
-
The final part of this message tells us where Rails has looked for the templates.
-
: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.
-
: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 first part identifies what template is missing
-
A controller is simply a class that is defined to inherit from ApplicationController. It's inside this class that you'll define methods that will become the actions for this controller. These actions will perform CRUD operations on the articles within our system.
-
resources :articles
do not omit "s"! when just type " resource :articles " then, :id is not shown in the"rake routes"
-
Rails provides a resources method which can be used to declare a standard REST resource.
-
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.
-
A view's purpose is to display this information in a human readable format. An important distinction to make is that it is the controller, not the view, where information is collected.
-
A controller's purpose is to receive specific requests for the application. Routing decides which controller receives which requests. Often, there is more than one route to each controller, and different routes can be served by different actions. Each action's purpose is to collect information to provide it to a view.
Tags
Annotators
URL
-