From 6330e2af11ee9531b1b0bcad25e5b97541623b40 Mon Sep 17 00:00:00 2001 From: eparreno Date: Fri, 28 May 2010 16:46:12 +0200 Subject: add <%= to fields_for examples --- railties/guides/source/action_view_overview.textile | 2 +- railties/guides/source/getting_started.textile | 2 +- railties/guides/source/nested_model_forms.textile | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile index 43ebe87875..8b5eda0973 100644 --- a/railties/guides/source/action_view_overview.textile +++ b/railties/guides/source/action_view_overview.textile @@ -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 %> diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index fe623e969f..46e709d0f5 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -1342,7 +1342,7 @@ We also add a @post.tags.build at the top of this form, this is to make Now create the folder app/views/tags and make a file in there called _form.html.erb which contains the form for the tag: -<% form.fields_for :tags do |tag_form| %> +<%= form.fields_for :tags do |tag_form| %>
<%= tag_form.label :name, 'Tag:' %> <%= tag_form.text_field :name %> diff --git a/railties/guides/source/nested_model_forms.textile b/railties/guides/source/nested_model_forms.textile index 4a79902232..39b0c32f24 100644 --- a/railties/guides/source/nested_model_forms.textile +++ b/railties/guides/source/nested_model_forms.textile @@ -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 %> -- cgit v1.2.3 From 82f67586b29b97de56a8d36569cd8477183d0623 Mon Sep 17 00:00:00 2001 From: eparreno Date: Mon, 31 May 2010 10:37:13 +0200 Subject: AR validations & callbacks: update callbacks list --- .../source/activerecord_validations_callbacks.textile | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/activerecord_validations_callbacks.textile b/railties/guides/source/activerecord_validations_callbacks.textile index 857551c9d5..d83ea57864 100644 --- a/railties/guides/source/activerecord_validations_callbacks.textile +++ b/railties/guides/source/activerecord_validations_callbacks.textile @@ -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+ +* +after_save+ * +before_create+ -* INSERT OPERATION +* +around_create+ * +after_create+ -* +after_save+ h4. Updating an Object * +before_validation+ -* +before_validation_on_update+ * +after_validation+ -* +after_validation_on_update+ * +before_save+ +* +after_save+ * +before_update+ -* UPDATE OPERATION +* +around_update+ * +after_update+ -* +after_save+ 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. -- cgit v1.2.3 From 158473f0d113f0c0b02ba9b7353c10949172a1f7 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 2 Jun 2010 00:28:23 +0200 Subject: AS guide: documents String#truncate --- .../source/active_support_core_extensions.textile | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'railties/guides/source') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 08fddd2926..de82e871a6 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -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+: + + +"Oh dear! Oh dear! I shall be late!".truncate(20) +# => "Oh dear! Oh dear!..." + + +Ellipsis can be customized with the +:omission+ option: + + +"Oh dear! Oh dear! I shall be late!".truncate(20, :omission => '…') +# => "Oh dear! Oh …" + + +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: + + +"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..." + + +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 % string operator supports key-based interpolation, both formatted and unformatted: -- cgit v1.2.3 From afc102698672cdf546a15424471d3287a39dbb06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 2 Jun 2010 08:45:03 +0200 Subject: Still copy application configuration to generator even if they are required earlier. Also tidy up the guide a little bit. --- railties/guides/source/generators.textile | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/generators.textile b/railties/guides/source/generators.textile index d3757e9733..b77a2837c3 100644 --- a/railties/guides/source/generators.textile +++ b/railties/guides/source/generators.textile @@ -322,14 +322,10 @@ config.generators do |g| g.template_engine :erb g.test_framework :shoulda, :fixture => false g.stylesheets false -end - - -And at the end of the same file: - -require 'rails/generators' -Rails::Generators.fallbacks[:shoulda] = :test_unit + # Add a fallback! + g.fallbacks[:should] = :test_unit +end Now, if create a Comment scaffold, you will see that shoulda generators are being invoked, and at the end, they are just falling back to test unit generators: @@ -361,7 +357,7 @@ $ rails generate scaffold Comment body:text create test/unit/helpers/comments_helper_test.rb -Such tool allows your generators to have single responsibility, increasing the code reuse and reducing the amount of code duplication. +Such tool allows your generators to have single responsibility, increasing the code reuse and reducing the amount of duplication. h3. Changelog -- cgit v1.2.3