title: Calling a method from a controller in Rails?
body: <p>I am a rails beginner and this simple question is really perplexing me.
  On every page, I want a list of all available pages in my app. So in layouts/application.html.erb I have the following code:</p>
  
  <pre><code>&lt;ul&gt;
  &lt;!-- This loop prints out links to all the pages --&gt;
  &lt;% @pages = Page.all %&gt;
  &lt;% @pages.each do |page| %&gt;
  &lt;li&gt;&lt;%= link_to page.name, page_path(page) %&gt;&lt;/li&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p></p>
  
  <p>This code DOES work, however I am not satisfied with it because it goes against MVC principles. Really instead of querying the database with &lt;% @pages = Page.all %>, I instead want to call the getpages method in the PagesController, which looks like this:</p>
  
  <pre><code>def getpages
      @pages = Page.all
  end
  </code></pre>
  
  <p>My first instinct was to replace &lt;% @pages = Page.all %> with &lt;% PagesController.getpages %>, which was unsuccessful.
  I am confident this problem has something to do with routing, could anyone enlighten me.</p>