Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When the view is being rendered, instance variables and their values are picked up from the controller and passed to the view initializer which sets them to the view instance. This is done using these ruby methods:</p> <p><code>instance_variables</code> - gets names of instance variables (<a href="http://ruby-doc.org/core-2.0.0/Object.html#method-i-instance_variables">documentation</a>) <code>instance_variable_get(variable_name)</code> - gets value of an instance variable (<a href="http://ruby-doc.org/core-2.0.0/Object.html#method-i-instance_variable_get">documentation</a>) <code>instance_variable_set(variable_name, variable_value)</code> - sets value of an instance variable (<a href="http://ruby-doc.org/core-2.0.0/Object.html#method-i-instance_variable_set">documentation</a>)</p> <p>Here is the Rails code:</p> <p>Collecting controller instance variables (<a href="https://github.com/rails/rails/blob/0c5552a3dd28e35cce64462765cc41c5355db0f1/actionpack/lib/abstract_controller/rendering.rb#L138-L145">github</a>):</p> <pre><code>def view_assigns hash = {} variables = instance_variables variables -= protected_instance_variables variables -= DEFAULT_PROTECTED_INSTANCE_VARIABLES variables.each { |name| hash[name[1..-1]] = instance_variable_get(name) } hash end </code></pre> <p>Passing them to the view (<a href="https://github.com/rails/rails/blob/0c5552a3dd28e35cce64462765cc41c5355db0f1/actionpack/lib/abstract_controller/rendering.rb#L84-L86">github</a>):</p> <pre><code>def view_context view_context_class.new(view_renderer, view_assigns, self) end </code></pre> <p>Setting them in the view (<a href="https://github.com/rails/rails/blob/f817bb2c485d7363be104fd8a00b28c36a0adefc/actionpack/lib/action_view/base.rb#L177-L179">github</a>):</p> <pre><code>def assign(new_assigns) # :nodoc: @_assigns = new_assigns.each { |key, value| instance_variable_set("@#{key}", value) } end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload