Forum: Ruby on Rails Layout not rendered when render_component used

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Mark Drayton (Guest)
on 2006-01-14 00:07
(Received via mailing list)

I've got a login action that handles authenticating users, setting
cookies and, via its view, displaying an HTML snippet containing a form
with username and password fields. It's called from the main
application.rhtml layout so I don't need to have a seperate page (away
from the main site) with a login form.

My user model is more-or-less the same as in the Agile RoR book.


class AuthController < ApplicationController
  layout false

  def login
    if request.get?
      @user =
      @user =[:user])
      logged_in_user = @user.try_to_login
      if logged_in_user
        # handle setting cookies, setting session
        # and redirecting to index
        flash[:loginerror] = 'Invalid username/password combination'


<div id="loginbox">
 <% if flash[:loginerror] %>
  <h3><%= flash[:loginerror] %></h3>
 <% end %>
 <%= form_tag :controller => 'auth', :action => 'login' %>
  <label for="user_name">name:</label>
  <%= text_field 'user', 'name' %><br />
  <label for="user_password">password:</label>
  <%= text_field 'user', 'password' %><br />
  <label for="login"></label>
  <input type="submit" name="login" id="login" value="go" />
 <%= end_form_tag %>


<% if session[:user] %>
 <h3>Hi, <%= session[:user].name %>.</h3>
<% else %>
 <%= render_component :controller => 'auth', :action => 'login' %>
<% end %>

When I GET an action that should be rendered with the application.rhtml
layout the login form appears with no problems. After submitting the
form (by POST), only the login view is rendered. No layout.

If I don't include the "layout false" line in AuthController the whole
thing gets stuck in a loop as the view calls the layout and the layout
calls the view, etc.

What am I doing wrong here? How can I get the output of the combined
auth action and view to be inserted into the main layout? Is this even
the right way of doing things? It feels like a reasonable approach but
I'm prepared to be told I'm completely wrong.

Thanks in advance,


Mark Drayton
This topic is locked and can not be replied to.