Define global variable rails
<p>Right now in my view I have this:</p>

<pre><code>@categories.each do |category|
</code></pre>

<p>And I need to define @categories in each method in controller duplicating the code.</p>

<pre><code>def home
  @categories = Category.where(:parent_id =&gt; '').order("id").each
end

def contacts
  @categories = Category.where(:parent_id =&gt; '').order("id").each
end
</code></pre>

<p>How do I get rid of repetition?</p>