title: Rails3: Rendering from another controller
body: <p>I am getting started with rails, so this is a fairly basic question.  I am trying to render a login form (authlogic) in the homepage, using this code:</p>
  
  <p>views/home/index.html.haml:</p>
  
  <pre><code>%p
    This is the home page...!
  
  - if current_user
  - else
    = render :template =&gt; 'user_sessions/new'
  </code></pre>
  
  <p><br/>
  user_sessions_controller:</p>
  
  <pre><code>class UserSessionsController &lt; ApplicationController
    before_filter :require_no_user, :only =&gt; [:new, :create]
    before_filter :require_user, :only =&gt; :destroy
  
    def new
      @user_session = UserSession.new
    end
  
    def create
      @user_session = UserSession.new(params[:user_session])
      if @user_session.save
        flash[:notice] = "Login successful!"
        redirect_back_or_default user_controls_url
      else
        render :action =&gt; :new
      end
    end
  
    def destroy
      current_user_session.destroy
      flash[:notice] = "Logout successful!"
      redirect_back_or_default home_url
    end
  end
  </code></pre>
  
  <p><br/>
  views/user_sessions/new.html.haml</p>
  
  <pre><code>= form_for @user_session, :url =&gt; {:action =&gt; "create"} do |f|
    = f.error_messages
    %div
      = f.label :login
      = f.text_field :login
    %div
      = f.label :password
      = f.password_field :password
    %div
      = f.check_box :remember_me
      = f.label :remember_me
    %div
      = f.submit "Login"
  </code></pre>
  
  <p><br/></p>
  
  <p>models/user_session.rb</p>
  
  <pre><code>class UserSession &lt; Authlogic::Session::Base
  
    def to_key
      new_record? ? nil : [ self.send(self.class.primary_key) ]
    end
  
    httponly true
    secure true
  end
  </code></pre>
  
  <p><br/>
  When I visit the homepage, I get:</p>
  
  <pre><code>ActionView::Template::Error (undefined method `model_name' for NilClass:Class):
  1: = form_for @user_session, :url =&gt; {:action =&gt; "create"} do |f|
  2:   = f.error_messages
  3:   %div
  4:     = f.label :login
    app/views/user_sessions/new.html.haml:1:in `_app_views_user_sessions_new_html_haml___182031841_97682750'
    app/views/home/index.html.haml:6:in `_app_views_home_index_html_haml__679857083_97787190'
  </code></pre>
  
  <p>What am I doing wrong, and how do I fix it?</p>
  
  <p>Thanks a lot for your help.</p>