419 Matching Annotations
- Jul 2015
-
guides.rubyonrails.org guides.rubyonrails.org
-
If you're going to need to use any other methods, you should use reversible or write the up and down methods instead of using the change method.
-
he change method supports only these migration definitions
-
If the helpers provided by Active Record aren't enough you can use the execute method to execute arbitrary SQL
-
Active Record only supports single column foreign keys. execute and structure.sql are required to use composite foreign keys.
-
Unlike change_column (and change_column_default), change_column_null is reversible.
-
change_column_default
-
change_column_null
-
change_column
-
add_column
-
remove_column
-
A close cousin of create_table is change_table, used for changing existing tables. It is used in a similar fashion to create_table but the object yielded to the block knows more tricks.
-
which are not created by default)
-
which creates a categories_products table with two columns called category_id and product_id.
-
If you need to pass database specific options you can place an SQL fragment in the :options option
-
By default, create_table will create a primary key called id. You can change the name of the primary key with the :primary_key option
-
The create_table method is one of the most fundamental, but most of the time, will be generated for you from using a model or scaffold generator
-
The model and scaffold generators will create migrations appropriate for adding a new model.
-
There is also a generator which will produce join tables if JoinTable is part of the name:
-
the generator accepts column type as references(also available as belongs_to)
-
If the migration name is of the form "CreateXXX" and is followed by a list of column names and types then a migration creating the table XXX with the columns listed will be generated
-
part_number:string
What kind of column datatype can be used in migration?
-
If you'd like to add an index on the new column
-
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.
-
The name of the migration class (CamelCased version) should match the latter part of the file name.
-
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.
-
Alternatively, you can use up and down instead of change:
-
If you wish for a migration to do something that Active Record doesn't know how to reverse, you can use reversible:
-
migrations are wrapped in a transaction
-
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.
-
The timestamps macro adds two columns, created_at and updated_at.
-
A primary key column called id will also be added implicitly,
-
each migration modifies it to add or remove tables, columns, or entries.
-
migration as being a new 'version' of the database
-
Migrations are a convenient way to alter your database schema over time in a consistent and easy way
-
-
api.rubyonrails.org api.rubyonrails.org
-
create_join_table does not create any indices by default;
-
The reference column is an integer by default
-
-
guides.rubyonrails.org guides.rubyonrails.org
-
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.
-
migrations
-
Rails provides a domain-specific language for managing a database schema
-
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.
-
they raise the exception ActiveRecord::RecordInvalid if validation fails
-
save! and update!
-
return false when validation fails and they didn't actually perform any operation on the database
-
save and update take it into account when running
-
Active Record allows you to validate the state of a model before it gets written into the database.
-
destroyed
-
retrieved
-
update_all
-
you'd like to update several records in bulk
-
A shorthand for this
-
.update
-
saved
-
modified
-
.where(name: 'David', occupation: 'Code Artist')
-
.find_by(name: 'David')
-
.first
-
.all
-
create and new will yield the new object to that block for initialization:
-
block
-
user.save will commit the record to the database
-
create and save a new record into the database
-
create
-
instantiated without being saved
-
new
-
Active Record objects can be created from a hash, a block or have their attributes manually set after creation
-
ActiveRecord::Base.table_name= method
-
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:
-
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
-
What if you need to follow a different naming convention or need to use your Rails application with a legacy database?
-
This will create a Product model, mapped to a products table at the database
-
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.
-
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.
-
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.
-
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).
-
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.
-
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.
-
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.
-
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.
-
is a technique that connects the rich objects of an application to tables in a relational database management system
-
Object-Relational Mapping,
-
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.
-
Active Record facilitates the creation and use of business objects whose data requires persistent storage to a database.
-
the layer of the system responsible for representing business data and logic
-
Active Record is the M in MVC
-
-
guides.rubyonrails.org guides.rubyonrails.org
-
The render method here is taking a very simple hash with a key of plain and value of params[:article].inspect.
-
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.
-
As the render method iterates over the @article.comments collection, it assigns each comment to a local variable named the same as the partial,
-
<%= render @article.comments %>
-
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.
-
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.
-
The form_for call here uses an array, which will build a nested route, such as /articles/1/comments.
-
form_for([@article, @article.comments.build])
-
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.
-
We pass the named route as the second argument,
-
The delete routing method should be used for routes that destroy resources
-
Resource-oriented style.
-
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.
-
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.
-
You need to tell the user that something went wrong.
-
we use render instead of redirect_to when save returns false.
-
The new action is now creating a new instance variable called @article, and you'll see why that is in just a few moments.
-
redirect_to @article
-
With the validation now in place, when you call @article.save on an invalid article, it will return false
-
These changes will ensure that all articles have a title that is at least five characters long.
-
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
-
link_to method is one of Rails' built-in view helpers.
-
:id tells rails that this route expects an :id parameter, which in our case will be the id of the article.
-
We have to whitelist our controller parameters to prevent wrongful mass assignment.
-
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.
-
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.
-
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.
-
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.
-
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
-
-
staruml.readthedocs.org staruml.readthedocs.org
-
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.
-
part of a project saved as a separate file with the extension name .mfj
-
A fragmen
-
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.
-
visual geometric symbolic representation of a software model
-
Diagram
-
description of any aspect of a software system such as structure, behavior, requirement, and so on
-
Model or software model
-
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.
-
-
api.jquery.com api.jquery.com
-
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
-
-
api.rubyonrails.org api.rubyonrails.org
-
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.
-
if @post is an existing record you wish to edit, you can create the form using
-
a form can be created by passing form_for a string or symbol representing the object we are concerned with:
-
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.
-
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].
-
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,
-
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.
-
-
api.rubyonrails.org api.rubyonrails.org
-
A FormBuilder object is associated with a particular model object and allows you to generate fields associated with the model object.
-
-
api.rubyonrails.org api.rubyonrails.org
-
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:
-
An action may contain only a single render or a single redirect. Attempting to try to do either again will result in a DoubleRenderError:
-
Redirects are used to move from one action to another.
-
It's automatically configured.
-
Action Controller sends content to the user by using one of five rendering methods.
-
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들은 브라우저가 켜져 있는 동안만 저장되는 것들이다.
-
Sessions allow you to store objects in between requests
-
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
-
For every request, the router determines the value of the controller and action keys.
-
These two methods represent the two basic action archetypes used in Action Controllers. Get-and-show and do-and-redirect.
-
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.
-
Unlike index, the create action will not render a template. After performing its main purpose (creating a new post), it initiates a redirect instead.
-
only the ApplicationController in a Rails application inherits from ActionController::Base. All other controllers in turn inherit from ApplicationController
-
- Oct 2014
-
www.transmography.net www.transmography.net
-
www.transmography.net www.transmography.net
-
cuum packed in workout get ups
-
her
-
-
www.transmography.net www.transmography.net
-
They’ve been classified as appliances.
-
warmth of humanity or the frigidity of automations.
-
“You are old enough to drink, right?”
-
-
www.transmography.net www.transmography.net
-
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
-
-
-
¶ 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.
-
Jolly Rancher blue liquid
-
The walls heaved like a fish’s gills
-
- Sep 2014
-
www.transmography.net www.transmography.net
-
¶ 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.
-
Plus, the thing had a steering wheel. Old school.
-
books
-
“274 miles charged, Dave.”
-
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.
-
Wrapped in her clean underwear
-
meting
sp error: meeting
-
-
www.transmography.net www.transmography.net
-
-
-
mall bubbles showed the places where fish had surfaced to pick off fallen bits of flesh.
-
¶ 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.
-
-
-
www.transmography.net www.transmography.net
-
¶ 6 Leave a comment on paragraph 6 0 Story here.
-