Layout not rendered when render_component used


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’


<% if flash[:loginerror] %>

<%= flash[:loginerror] %>

<% end %> <%= form_tag :controller => 'auth', :action => 'login' %> name: <%= text_field 'user', 'name' %>
password: <%= text_field 'user', 'password' %>
<%= end_form_tag %>


<% if session[:user] %>

Hi, <%= session[:user].name %>.

<% 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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs