Getting Started with Rails - Ruby on Rails Guides - 0 views
-
A controller's purpose is to receive specific requests for the application.
- ...55 more annotations...
-
view templates are written in a language called ERB (Embedded Ruby) which is converted by the request cycle in Rails before being sent to the user.
-
routing file which holds entries in a special DSL (domain-specific language) that tells Rails how to connect incoming requests to controllers and actions.
-
You can create, read, update and destroy items for a resource and these operations are referred to as CRUD operations
-
If not found, then it will attempt to load a template called application/new. It looks for one here because the PostsController inherits from ApplicationController
-
: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.
-
When you call form_for, you pass it an identifying object for this form. In this case, it's the symbol :post. This tells the form_for helper what this form is for.
-
parameters can then be referenced inside the controller actions, typically to perform a particular task
-
Rails uses rake commands to run migrations, and it's possible to undo a migration after it's been applied to your database
-
every Rails model can be initialized with its respective attributes, which are automatically mapped to the respective database columns.
-
The action defined in this method is also reversible, which means Rails knows how to reverse the change made by this migration, in case you want to reverse it later
-
Migration filenames include a timestamp to ensure that they're processed in the order that they were created.
-
prevents an attacker from setting the model's attributes by manipulating the hash passed to the model.
-
If you want to link to an action in the same controller, you don't need to specify the :controller option, as Rails will use the current controller by default.
-
Active Record supplies a great deal of functionality to your Rails models for free, including basic database CRUD (Create, Read, Update, Destroy) operations, data validation, as well as sophisticated search support and the ability to relate multiple models to one another.
-
Rails can validate a variety of conditions in a model, including the presence or uniqueness of columns, their format, and the existence of associated objects.
-
Each request for a comment has to keep track of the post to which the comment is attached, thus the initial call to the find method of the Post model to get the post in question.
-
pluralize is a rails helper that takes a number and a string as its arguments. If the number is greater than one, the string will be automatically pluralized.
-
The render method is used so that the @post object is passed back to the new template when it is rendered.
-
The method: :patch option tells Rails that we want this form to be submitted via the PATCH HTTP method which is the HTTP method you're expected to use to update resources according to the REST protocol.
-
The :method and :'data-confirm' options are used as HTML5 attributes so that when the link is clicked, Rails will first show a confirm dialog to the user, and then submit the link with method delete. This is done via the JavaScript file jquery_ujs which is automatically included into your application's layout (app/views/layouts/application.html.erb) when you generated the application.
-
standard CRUD actions in each controller in the following order: index, show, new, edit, create, update and destroy.