diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-10-08 07:46:23 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-10-08 07:46:23 +0000 |
commit | 8ba8c7c560397b783743a662789fedcf85855ce2 (patch) | |
tree | 6444e462311f23caae2e0a938e861007074b9ca0 /actionpack | |
parent | 0c3c131f3b9a82d3e2f36b2930c3437c9f821b6d (diff) | |
download | rails-8ba8c7c560397b783743a662789fedcf85855ce2.tar.gz rails-8ba8c7c560397b783743a662789fedcf85855ce2.tar.bz2 rails-8ba8c7c560397b783743a662789fedcf85855ce2.zip |
cleanup of local_assigns handling and documentation update (closes #6358) [skaes]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5231 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/base.rb | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 53811d8e9d..e0bd591550 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -53,13 +53,22 @@ module ActionView #:nodoc: # # You can pass local variables to sub templates by using a hash with the variable names as keys and the objects as values: # - # <%= render "shared/header", { "headline" => "Welcome", "person" => person } %> + # <%= render "shared/header", { :headline => "Welcome", :person => person } %> # # These can now be accessed in shared/header with: # # Headline: <%= headline %> # First name: <%= person.first_name %> # + # If you need to find out whether a certain local variable has been assigned a value in a particular render call, + # you need to use the following pattern: + # + # <% if local_assigns.has_key? :headline %> + # Headline: <%= headline %> + # <% end %> + # + # Testing using <tt>defined? headline</tt> will not work. This is an implementation restriction. + # # == Template caching # # By default, Rails will compile each template to a method in order to render it. When you alter a template, Rails will @@ -301,6 +310,9 @@ module ActionView #:nodoc: # will only be read if it has to be compiled. # def compile_and_render_template(extension, template = nil, file_path = nil, local_assigns = {}) #:nodoc: + # convert string keys to symbols if requested + local_assigns = local_assigns.symbolize_keys if @@local_assigns_support_string_keys + # compile the given template, if necessary if compile_template?(template, file_path, local_assigns) template ||= read_template_file(file_path, extension) @@ -311,8 +323,6 @@ module ActionView #:nodoc: method_name = @@method_names[file_path || template] evaluate_assigns - local_assigns = local_assigns.symbolize_keys if @@local_assigns_support_string_keys - send(method_name, local_assigns) do |*name| instance_variable_get "@content_for_#{name.first || 'layout'}" end @@ -427,8 +437,8 @@ module ActionView #:nodoc: if @@compile_time[render_symbol] && supports_local_assigns?(render_symbol, local_assigns) if file_name && !@@cache_template_loading - @@compile_time[render_symbol] < File.mtime(file_name) || (File.symlink?(file_name) ? - @@compile_time[render_symbol] < File.lstat(file_name).mtime : false) + @@compile_time[render_symbol] < File.mtime(file_name) || + (File.symlink?(file_name) && (@@compile_time[render_symbol] < File.lstat(file_name).mtime)) end else true @@ -457,7 +467,7 @@ module ActionView #:nodoc: locals_code = "" locals_keys.each do |key| - locals_code << "#{key} = local_assigns[:#{key}] if local_assigns.has_key?(:#{key})\n" + locals_code << "#{key} = local_assigns[:#{key}]\n" end "def #{render_symbol}(local_assigns)\n#{locals_code}#{body}\nend" |