395 Matching Annotations
  1. Jul 2015
    1. 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.
    2. The name of the migration class (CamelCased version) should match the latter part of the file name.
    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.
    4. Alternatively, you can use up and down instead of change:
    5. If you wish for a migration to do something that Active Record doesn't know how to reverse, you can use reversible:
    6. migrations are wrapped in a transaction
    7. If the database does not support this then when a migration fails the parts of it that succeeded will not be rolled back. You will have to rollback the changes that were made by hand.
    8. The timestamps macro adds two columns, created_at and updated_at.
    9. A primary key column called id will also be added implicitly,
    10. each migration modifies it to add or remove tables, columns, or entries.
    11. migration as being a new 'version' of the database
    12. Migrations are a convenient way to alter your database schema over time in a consistent and easy way
    1. Rails keeps track of which files have been committed to the database and provides rollback features. To actually create the table, you'd run rake db:migrate and to roll it back, rake db:rollback.
    2. migrations
    3. Rails provides a domain-specific language for managing a database schema
    4. This enables you to add behavior to your models by transparently executing code when those events occur, like when you create a new record, update it, destroy it and so on.
    5. they raise the exception ActiveRecord::RecordInvalid if validation fails
    6. save! and update!
    7. return false when validation fails and they didn't actually perform any operation on the database
    8. save and update take it into account when running
    9. Active Record allows you to validate the state of a model before it gets written into the database.
    10. destroyed
    11. retrieved
    12. update_all
    13. you'd like to update several records in bulk
    14. A shorthand for this
    15. .update
    16. saved
    17. modified
    18. .where(name: 'David', occupation: 'Code Artist')
    19. .find_by(name: 'David')
    20. .first
    21. .all
    22. create and new will yield the new object to that block for initialization:
    23. block
    24. user.save will commit the record to the database
    25. create and save a new record into the database
    26. create
    27. instantiated without being saved
    28. new
    29. Active Record objects can be created from a hash, a block or have their attributes manually set after creation
    30. ActiveRecord::Base.table_name= method
    31. It's also possible to override the column that should be used as the table's primary key using the ActiveRecord::Base.primary_key= method:
    32. If you do so, you will have to define manually the class name that is hosting the fixtures (my_products.yml) using the set_fixture_class method in your test definition
    33. What if you need to follow a different naming convention or need to use your Rails application with a legacy database?
    34. This will create a Product model, mapped to a products table at the database
    35. While these column names are optional, they are in fact reserved by Active Record. Steer clear of reserved keywords unless you want the extra functionality.
    36. 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.
    37. 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.
    38. Database Table - Plural with underscores separating words (e.g., book_clubs). Model Class - Singular with the first letter of each word capitalized (e.g., BookClub).
    39. Rails will pluralize your class names to find the respective database table. So, for a class Book, you should have a database table called books.
    40. 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.
    41. 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.
    42. 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.
    43. is a technique that connects the rich objects of an application to tables in a relational database management system
    44. Object-Relational Mapping,
    45. Active Record takes the opinion that ensuring data access logic as part of the object will educate users of that object on how to write to and read from the database.
    46. Active Record facilitates the creation and use of business objects whose data requires persistent storage to a database.
    47. the layer of the system responsible for representing business data and logic
    48. Active Record is the M in MVC
    1. The render method here is taking a very simple hash with a key of plain and value of params[:article].inspect.
    2. 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.
    3. As the render method iterates over the @article.comments collection, it assigns each comment to a local variable named the same as the partial,
    4. <%= render @article.comments %>
    5. 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.
    6. 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.
    7. The form_for call here uses an array, which will build a nested route, such as /articles/1/comments.
    8. form_for([@article, @article.comments.build])
    9. if you have an instance variable @article containing an article, you can retrieve all the comments belonging to that article as an array using @article.comments.
    10. We pass the named route as the second argument,
    11. The delete routing method should be used for routes that destroy resources
    12. Resource-oriented style.
    13. 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.
    14. 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.
    15. You need to tell the user that something went wrong.
    16. we use render instead of redirect_to when save returns false.
    17. The new action is now creating a new instance variable called @article, and you'll see why that is in just a few moments.
    18. redirect_to @article
    19. With the validation now in place, when you call @article.save on an invalid article, it will return false
    20. These changes will ensure that all articles have a title that is at least five characters long.
    21. 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
    22. link_to method is one of Rails' built-in view helpers.
    23. :id tells rails that this route expects an :id parameter, which in our case will be the id of the article.
    24. We have to whitelist our controller parameters to prevent wrongful mass assignment.
    25. The ability to grab and automatically assign all controller parameters to your model in one shot makes the programmer's job easier, but this convenience also allows malicious use.
    26. 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.
    27. 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.
    28. Then, @article.save is responsible for saving the model in the database. Finally, we redirect the user to the show action, which we'll define later.
    29. every Rails model can be initialized with its respective attributes, which are automatically mapped to the respective database columns
    30. command will apply to the database defined in the development section of your config/database.yml file
    31. 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.
    32. 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
    33. a text attribute of type text.
    34. a title attribute of type string
    35. we want a Article model,
    36. database tables use a plural name.
    37. Models in Rails use a singular name
    38. When a form is submitted, the fields of the form are sent to Rails as parameters.
    39. This is associated with the create action of the current controller
    40. the form will (by default) send a POST request
    41. The articles_path helper tells Rails to point the form to the URI Pattern associated with the articles prefix
    42. 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.
    43. When you call form_for, you pass it an identifying object for this form.
    44. handler must be one of erb, builder or coffee.
    45. format for this template can only be html
    46. second extension is the handler that will be used.
    47. the first extension is the format of the template
    48. app/views/articles/new.html.erb.
    49. The final part of this message tells us where Rails has looked for the templates.
    50. :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.
    51. :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.
    52. The first part identifies what template is missing
    53. 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.
    54. resources :articles

      do not omit "s"! when just type " resource :articles " then, :id is not shown in the"rake routes"

    55. Rails provides a resources method which can be used to declare a standard REST resource.
    56. 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.
    57. 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.
    58. 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. part of a project saved as a separate file with the extension name .mfj
    3. A fragmen
    4. 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.
    5. visual geometric symbolic representation of a software model
    6. Diagram
    7. description of any aspect of a software system such as structure, behavior, requirement, and so on
    8. Model or software model
    9. 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. If a string is passed as the parameter to $(), jQuery examines the string to see if it looks like HTML (i.e., it starts with <tag ... >). If not, the string is interpreted as a selector expression
    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. if @post is an existing record you wish to edit, you can create the form using
    3. a form can be created by passing form_for a string or symbol representing the object we are concerned with:
    4. 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.
    5. This means that when the form is submitted, the value entered by the user will be available in the controller as params[:person][:first_name].
    6. 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,
    7. The method can be used in several slightly different ways, depending on how much you wish to rely on Rails to infer automatically from the model how the form should be constructed.
    1. A FormBuilder object is associated with a particular model object and allows you to generate fields associated with the model object.
    1. You don't have to rely on the automated rendering. For example, actions that could result in the rendering of different templates will use the manual rendering methods:
    2. An action may contain only a single render or a single redirect. Attempting to try to do either again will result in a DoubleRenderError:
    3. Redirects are used to move from one action to another.
    4. It's automatically configured.
    5. Action Controller sends content to the user by using one of five rendering methods.
    6. 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들은 브라우저가 켜져 있는 동안만 저장되는 것들이다.

    7. Sessions allow you to store objects in between requests
    8. All request parameters, whether they come from a GET or POST request, or from the URL, are available through the params method which returns a hash
    9. For every request, the router determines the value of the controller and action keys.
    10. These two methods represent the two basic action archetypes used in Action Controllers. Get-and-show and do-and-redirect.
    11. Actions, by default, render a template in the app/views directory corresponding to the name of the controller and action after executing code in the action.
    12. Unlike index, the create action will not render a template. After performing its main purpose (creating a new post), it initiates a redirect instead.
    13. only the ApplicationController in a Rails application inherits from ActionController::Base. All other controllers in turn inherit from ApplicationController
  2. Oct 2014
    1. I saw the time you took that photo of Trevor with all the hearts drawn around the frame with you to bed and rubbed it underneath your panties
    2. ¶ 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. Jolly Rancher blue liquid
    4. The walls heaved like a fish’s gills
  3. Sep 2014
    1. ¶ 53 Leave a comment on paragraph 53 0 Sass could remember back when that was a thing, not so long ago, before the civic groups found much more pressing uses for their dollars. Back before the Defederation.
    2. Plus, the thing had a steering wheel. Old school.
    3. books
    4. “274 miles charged, Dave.”
    5. An extra passenger would mean an extra fee, and that was money she didn’t have. She doesn’t know how the kid could even afford it; his parents must be loaded.
    6. Wrapped in her clean underwear
    7. meting

      sp error: meeting

    1. mall bubbles showed the places where fish had surfaced to pick off fallen bits of flesh.
    2. ¶ 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.
  4. www.transmography.net www.transmography.net
    1. ¶ 4 Leave a comment on paragraph 4 1 By centralizing the peer review experience with The Portal, it is my goal to make the task of reading and commenting on submissions an interactive and engaging experience, with a graceful learning curve. Furthermore, I hope to foster accountability amongst the workshop participants for thoughtful and thought-provoking feedback; I believe that an aesthetically pleasing GUI (graphic user interface) and intuitive digital tools can be a motivating force, where as the constant email shuffle of documents or DropBox and Track Changes can be tiresome and mundane.
    2. ¶ 4 Leave a comment on paragraph 4 1 By centralizing the peer review experience with The Portal, it is my goal to make the task of reading and commenting on submissions an interactive and engaging experience, with a graceful learning curve. Furthermore, I hope to foster accountability amongst the workshop participants for thoughtful and thought-provoking feedback; I believe that an aesthetically pleasing GUI (graphic user interface) and intuitive digital tools can be a motivating force, where as the constant email shuffle of documents or DropBox and Track Changes can be tiresome and mundane.
    3. ¶ 4 Leave a comment on paragraph 4 1 By centralizing the peer review experience with The Portal, it is my goal to make the task of reading and commenting on submissions an interactive and engaging experience, with a graceful learning curve. Furthermore, I hope to foster accountability amongst the workshop participants for thoughtful and thought-provoking feedback; I believe that an aesthetically pleasing GUI (graphic user interface) and intuitive digital tools can be a motivating force, where as the constant email shuffle of documents or DropBox and Track Changes can be tiresome and mundane.
    4. “[G]ives readers the power to annotate, gloss, workshop, debate: with CommentPress you can do all of these things on a finer-grained level, turning a document into a conversation.”
    5. If you like writing in the margins or highlighting important sentences in printed documents, then The Portal will give you the digital equivalent that experience.
    6. ¶ 4Leave a comment on paragraph 41 By centralizing the peer review experience with The Portal, it is my goal to make the task of reading and commenting on submissions an interactive and engaging experience, with a graceful learning curve. Furthermore, I hope to foster accountability amongst the workshop participants for thoughtfu
    7. If you like writing in the margins or highlighting important sentences in printed documents, then The Portal will give you the digital equivalent that experience.
    8. ¶ 1 Leave a comment on paragraph 1 1 Welcome to the oasis of the virtual!
    9. ¶ 3 Leave a comment on paragraph 3 0 Using my background in new media scholarship, I have been able to bring digital scholarly tools to our speculative fiction writing workshop.
    10. ¶ 3 Leave a comment on paragraph 3 0 Using my background in new media scholarship, I have been able to bring digital scholarly tools to our speculative fiction writing workshop.
    11. Readers will then have the power to highlight and comment paragraph-by-paragraph or line-by-line in the margins of a text
    12. Readers will then have the power to highlight and comment paragraph-by-paragraph or line-by-line in the margins of a text
    1. Lorem ipsum.
    2. ¶ 2 Leave a comment on paragraph 2 0 Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum. Lorem ipsum.