420 Matching Annotations
  1. Jul 2015
    1. Sometimes your migration will do something which is just plain irreversible; for example, it might destroy some data. In such cases, you can raise ActiveRecord::IrreversibleMigration in your down block.
    2. If the migration name is of the form "AddXXXToYYY" or "RemoveXXXFromYYY" and is followed by a list of column names and types then a migration containing the appropriate add_column and remove_column statements will be created.
    3. Rails uses this timestamp to determine which migration should be run and in what order, so if you're copying a migration from another application or generate a file yourself, be aware of its position in the order.
    1. created_at - Automatically gets set to the current date and time when the record is first created. updated_at - Automatically gets set to the current date and time whenever the record is updated. lock_version - Adds optimistic locking to a model. type - Specifies that the model uses Single Table Inheritance. (association_name)_type - Stores the type for polymorphic associations. (table_name)_count - Used to cache the number of belonging objects on associations. For example, a comments_count column in a Articles class that has many instances of Comment will cache the number of existent comments for each article.
    2. Foreign keys - These fields should be named following the pattern singularized_table_name_id (e.g., item_id, order_id). These are the fields that Active Record will look for when you create associations between your models. Primary keys - By default, Active Record will use an integer column named id as the table's primary key. When using Active Record Migrations to create your tables, this column will be automatically created.
    3. When writing applications using other programming languages or frameworks, it may be necessary to write a lot of configuration code. This is particularly true for ORM frameworks in general. However, if you follow the conventions adopted by Rails, you'll need to write very little configuration (in some case no configuration at all) when creating Active Record models.
    4. Represent models and their data. Represent associations between these models. Represent inheritance hierarchies through related models. Validate models before they get persisted to the database. Perform database operations in an object-oriented fashion.
    5. Using ORM, the properties and relationships of the objects in an application can be easily stored and retrieved from a database without writing SQL statements directly and with less overall database access code.
    1. In the ArticlesController we need to have a way to block access to the various actions if the person is not authenticated. Here we can use the Rails http_basic_authenticate_with method, which allows access to the requested action if that method allows it.
    2. In addition, the code takes advantage of some of the methods available for an association. We use the create method on @article.comments to create and save the comment. This will automatically link the comment so that it belongs to that particular article.
    3. You'll see a bit more complexity here than you did in the controller for articles. That's a side-effect of the nesting that you've set up. Each request for a comment has to keep track of the article to which the comment is attached, thus the initial call to the find method of the Article model to get the article in question.
    4. The reason we can use this shorter, simpler form_for declaration to stand in for either of the other forms is that @article is a resource corresponding to a full set of RESTful routes, and Rails is able to infer which URI and method to use.
    5. Our edit page looks very similar to the new page; in fact, they both share the same code for displaying the form. Let's remove this duplication by using a view partial. By convention, partial files are prefixed with an underscore.
    6. Article class inherits from ActiveRecord::Base. 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
    7. Rails has several security features that help you write secure applications, and you're running into one of them now. This one is called strong parameters, which requires us to tell Rails exactly which parameters are allowed into our controller actions.
    8. You might be wondering why the A in Article.new is capitalized above, whereas most other references to articles in this guide have used lowercase. In this context, we are referring to the class named Article that is defined in \models\article.rb. Class names in Ruby must begin with a capital letter.
    9. 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.
    10. 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.
    11. :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.
    12. 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.
    13. 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.
    14. 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.
    1. UML (Unified Modeling Language) is so general-purpose modeling language that could be used to express any kinds of software-intensive systems. In this reason, using UML for a specific domain or platform is not sufficient, so you may need to define UML Profile.
    2. A model element typically may have multiple corresponding view elements. Model element have its own data such as name, stereotype, type, etc. View element just renders the corresponding model element in a diagram. View elements may exists multiple times in a diagram or different diagrams.
    3. Many users are confusing the difference between diagramming or drawing tool such as Microsoft Visio and modeling tools such StarUML or Rational Software Architect. First you need to understand a diagram is not a model.
    1. This behaves in almost the same way as outlined previously, with a couple of small exceptions. First, the prefix used to name the input elements within the form (hence the key that denotes them in the params hash) is actually derived from the object's class, e.g. params[:post] if the object's class is Post. However, this can be overwritten using the :as option, e.g. -

      <%= form_for(@person, as: :client) do |f| %> is not working

      <%= form_for @person, as: :client do |f| %> is right syntax.

    2. For fields generated in this way using the FormBuilder, if :person also happens to be the name of an instance variable @person, the default value of the field shown when the form is initially displayed (e.g. in the situation where you are editing an existing record) will be the value of the corresponding attribute of @person.
    3. The variable f yielded to the block is a FormBuilder object that incorporates the knowledge about the model object represented by :person passed to form_for. Methods defined on the FormBuilder are used to generate fields bound to this model. Thus, for example,
    1. This is useful for objects that are not yet ready to be persisted, such as a Signup object constructed in a multi-paged process, or objects that don't change much and are needed all the time, such as a User object for a system that requires login.

      objects that are ready to be persisted 한 것들은, server에 지속적으로 저장되는 객체들로 생각할 수 있다. 반면 session에 저장되는 obejct들은 브라우저가 켜져 있는 동안만 저장되는 것들이다.

  2. Oct 2014
    1. ¶ 90 Leave a comment on paragraph 90 0 Clara fixed her eyes on the sliver of moonlight flickering in the window. She remembered fishing with her father for starfish late one night. The moonlight spread out over the water and the whole ocean looked like a giant saucer full of milk ready to be lapped up. As her father dipped the net down into the water over and over, jellyfish would unspool their tentacles in clouds of green and purple. She worried that they were getting tangled in the net, but her father reassured her that the jellyfish were smart enough to know better, that they’d coexisted side-by-side with nets for years. Far below the jellyfish, where the sea congealed into a murky thickness, she saw a pair of red eyes glimmering. Beneath the eyes was a body, flat like a stingray, but much wider, so wide she couldn’t see either edge of the body.
  3. Sep 2014
    1. ¶ 1 Leave a comment on paragraph 1 0 Ella found Nathan’s body in the morning, beneath the shade of a cypress tree. From a distance he looked in the midst of a peaceful sleep, hands folded in his lap, head resting against rough bark. Gnarled roots shaped a throne around him, cushioned with thick Spanish moss.