title: Does accessing the database in views via view-models or view-helpers break the MVC paradigm?
body: <p>I believe all of the following break the MVC paradigm but wanted to double check if this was the case.  In all cases the view is directly accessing data rather than having the data being passed in. From my understanding of MVC, it should never do that.  The controller should get all the data that is necessary to render the view as to not couple the view and model directly.  Is my understanding correct?</p>
  
  <ol>
  <li><p>Accessing the database through a view helper</p>
  
  <pre><code># in app/helpers/view_helper.hrb
  def some_view_helper(person_id)
    @person = Person.find(person_id)
  end
  </code></pre></li>
  <li><p>Accessing another web server through a view helper</p>
  
  <pre><code># in app/helpers/view_helper.hrb
  def another_view_helper(person_id)
    # makes http request over the wire to get json back
    @json = WebService.get_person(person_id)
  end
  </code></pre></li>
  <li><p>Accessing the database through a view model</p>
  
  <pre><code># in apps/controller/person_controller.rb
  def show
    @person = Person.find(params[:id])
    @page_model = PageModel.new(@person)
  end
  
  #in app/views/persons/show.html.erb
  &lt;% @page_model.friends.each do |friend| %&gt;
    ...
  &lt;% end %&gt;
  
  #in app/models/person.rb
  class Person &lt; ActiveRecord::Base
    has_many :friends
  end
  
  #in app/models/page_models/page_model.rb
  def initialize(person)
    @person = person
  end
  
  def friends
    @person.friends
  end
  </code></pre></li>
  <li><p>Accessing web server to get data through a view model</p>
  
  <pre><code># in apps/controller/person_controller.rb
  def show
    @person = Person.find(params[:id])
    @page_model = PageModel.new(@person)
  end
  
  #in app/views/persons/show.html.erb
  &lt;% @page_model.friends.each do |friend| %&gt;
     ...
  &lt;% end %&gt;
  
  #in app/models/page_models/page_model.rb
  def initialize(person)
    @person = person
  end
  
  def friends
    WebService.get_friends_for_person(person_id)
  end
  </code></pre></li>
  </ol>