Merge remote branch 'docrails/master'
This commit is contained in:
commit
fdd203f964
@ -699,7 +699,7 @@ Creates a scope around a specific model object like form_for, but doesn‘t crea
|
||||
First name: <%= person_form.text_field :first_name %>
|
||||
Last name : <%= person_form.text_field :last_name %>
|
||||
|
||||
<% fields_for @person.permission do |permission_fields| %>
|
||||
<%= fields_for @person.permission do |permission_fields| %>
|
||||
Admin? : <%= permission_fields.check_box :admin %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
@ -1254,6 +1254,39 @@ There's also the destructive version +String#squish!+.
|
||||
|
||||
NOTE: Defined in +active_support/core_ext/string/filters.rb+.
|
||||
|
||||
h4. +truncate+
|
||||
|
||||
The method +truncate+ returns a copy of its receiver truncated after a given +length+:
|
||||
|
||||
<ruby>
|
||||
"Oh dear! Oh dear! I shall be late!".truncate(20)
|
||||
# => "Oh dear! Oh dear!..."
|
||||
</ruby>
|
||||
|
||||
Ellipsis can be customized with the +:omission+ option:
|
||||
|
||||
<ruby>
|
||||
"Oh dear! Oh dear! I shall be late!".truncate(20, :omission => '…')
|
||||
# => "Oh dear! Oh …"
|
||||
</ruby>
|
||||
|
||||
Note in particular that truncation takes into account the length of the omission string.
|
||||
|
||||
Pass a +:separator+ to truncate the string at a natural break:
|
||||
|
||||
<ruby>
|
||||
"Oh dear! Oh dear! I shall be late!".truncate(18)
|
||||
# => "Oh dear! Oh dea..."
|
||||
"Oh dear! Oh dear! I shall be late!".truncate(18, :separator => ' ')
|
||||
# => "Oh dear! Oh..."
|
||||
</ruby>
|
||||
|
||||
In the above example "dear" gets cut first, but then +:separator+ prevents it.
|
||||
|
||||
WARNING: The option +:separator+ can't be a regexp.
|
||||
|
||||
NOTE: Defined in +active_support/core_ext/string/filters.rb+.
|
||||
|
||||
h4. Key-based Interpolation
|
||||
|
||||
In Ruby 1.9 the <tt>%</tt> string operator supports key-based interpolation, both formatted and unformatted:
|
||||
|
@ -879,32 +879,28 @@ Here is a list with all the available Active Record callbacks, listed in the sam
|
||||
h4. Creating an Object
|
||||
|
||||
* +before_validation+
|
||||
* +before_validation_on_create+
|
||||
* +after_validation+
|
||||
* +after_validation_on_create+
|
||||
* +before_save+
|
||||
* +before_create+
|
||||
* INSERT OPERATION
|
||||
* +after_create+
|
||||
* +after_save+
|
||||
* +before_create+
|
||||
* +around_create+
|
||||
* +after_create+
|
||||
|
||||
h4. Updating an Object
|
||||
|
||||
* +before_validation+
|
||||
* +before_validation_on_update+
|
||||
* +after_validation+
|
||||
* +after_validation_on_update+
|
||||
* +before_save+
|
||||
* +before_update+
|
||||
* UPDATE OPERATION
|
||||
* +after_update+
|
||||
* +after_save+
|
||||
* +before_update+
|
||||
* +around_update+
|
||||
* +after_update+
|
||||
|
||||
h4. Destroying an Object
|
||||
|
||||
* +before_destroy+
|
||||
* DELETE OPERATION
|
||||
* +after_destroy+
|
||||
* +around_destroy+
|
||||
|
||||
WARNING. +after_save+ runs both on create and update, but always _after_ the more specific callbacks +after_create+ and +after_update+, no matter the order in which the macro calls were executed.
|
||||
|
||||
|
@ -1342,7 +1342,7 @@ We also add a <tt>@post.tags.build</tt> at the top of this form, this is to make
|
||||
Now create the folder <tt>app/views/tags</tt> and make a file in there called <tt>_form.html.erb</tt> which contains the form for the tag:
|
||||
|
||||
<erb>
|
||||
<% form.fields_for :tags do |tag_form| %>
|
||||
<%= form.fields_for :tags do |tag_form| %>
|
||||
<div class="field">
|
||||
<%= tag_form.label :name, 'Tag:' %>
|
||||
<%= tag_form.text_field :name %>
|
||||
|
@ -143,7 +143,7 @@ Now add a nested form for the +address+ association:
|
||||
<%= form_for @person do |f| %>
|
||||
<%= f.text_field :name %>
|
||||
|
||||
<% f.fields_for :address do |af| %>
|
||||
<%= f.fields_for :address do |af| %>
|
||||
<%= f.text_field :street %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
@ -184,7 +184,7 @@ The form code for an association collection is pretty similar to that of a singl
|
||||
<%= form_for @person do |f| %>
|
||||
<%= f.text_field :name %>
|
||||
|
||||
<% f.fields_for :projects do |pf| %>
|
||||
<%= f.fields_for :projects do |pf| %>
|
||||
<%= f.text_field :name %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
Loading…
Reference in New Issue
Block a user