# Can't handle \<% if logged\_in? %\> when running for the first time

**URL:** <https://www.ruby-forum.com/t/cant-handle-if-logged-in-when-running-for-the-first-time/135100>\
**Category:** Rails\
**Created:** [April 17, 2008, 9:51pm UTC](https://www.ruby-forum.com/t/cant-handle-if-logged-in-when-running-for-the-first-time/135100 "2008-04-17T21:51:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mister\_Blood\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@Mister\_Blood\_R](https://www.ruby-forum.com/u/Mister_Blood_R)\
**Post date:** [April 17, 2008, 9:51pm UTC](https://www.ruby-forum.com/t/cant-handle-if-logged-in-when-running-for-the-first-time/135100/1 "2008-04-17T21:51:02Z")

</div>

My app can’t handle \<% if logged\_in? %\> when running for the first  
time. It has no registered users, but why does it have to complain? It  
handles everything just fine after I register the first user manually  
through [www.mysite.com/users/new](http://www.mysite.com/users/new).

Processing MainController#index (for 127.0.0.1 at 2008-04-14 01:30:13)  
[GET]  
Session ID:  
BAh7CjoMY3NyZl9pZCIlYTNiMmY5ZDFmMjJhOWJhZDhhMTI1YzQxYzkzNDI5%0ANzg6CnRpdGxlewA6CXVzZXJpBjoOcmV0dXJuX3RvMCIKZmxhc2hJQzonQWN0%0AaW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA  
%3D%3D–346cfed42d9b4cc6e1dfc4f4d95ae774e5e9dc48  
Parameters: {“action”=\>“index”, “controller”=\>“main”}  
ParentCategory Load (0.002000) SELECT \* FROM `parent_categories`  
ORDER BY name ASC  
Category Load (0.006000) SELECT \* FROM `categories` ORDER BY name  
ASC  
Rendering template within layouts/application  
Rendering main/index  
Rendered layouts/\_header\_1 (0.00200)  
Site Load (0.002000) SELECT \* FROM `sites` WHERE (host = ‘127.0.0.1’  
or host = ‘’)

ActionView::TemplateError (Site::UndefinedError) on line #3 of layouts/  
\_footer.html.erb:  
1:

  
2: 
  
3: \<% if logged\_in? %\>  
4: \<% if admin? %\>  
5: - \<%= link\_to ‘admin’[], admin\_path %\>
  
6: \<% end %\>  
7: - \<%= link\_to ‘logout’[], logout\_path(:to =\>  
CGI.escape(request.request\_uri)) %\>

```
lib/authenticated_system.rb:4:in `current_site'
lib/authenticated_system.rb:103:in `login_from_session'
lib/authenticated_system.rb:16:in `current_user'
lib/authenticated_system.rb:10:in `logged_in?'
(eval):2:in `send'
(eval):2:in `logged_in?'
app/views/layouts/_footer_1.html.erb:3:in

```

`_run_erb_47app47views47layouts47_footer_146html46erb' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/ base.rb:637:in `send’  
/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_view/  
base.rb:637:in `compile_and_render_template' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/ base.rb:365:in `render\_template’  
/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_view/  
base.rb:316:in `render_file' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/ base.rb:331:in `render’  
/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_view/  
partials.rb:117:in `render_partial' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ benchmarking.rb:26:in `benchmark’  
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/lib/ruby/1.8/benchmark.rb:307:in `realtime’  
/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
benchmarking.rb:26:in `benchmark' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/ partials.rb:116:in `render\_partial’  
/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_view/  
base.rb:352:in `render' app/views/main/index.html.erb:239:in `\_run\_erb\_47app47views47main47index46html46erb’  
/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_view/  
base.rb:637:in `send' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/ base.rb:637:in `compile\_and\_render\_template’  
/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_view/  
base.rb:365:in `render_template' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/ base.rb:316:in `render\_file’  
/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
base.rb:1100:in `render_for_file' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ base.rb:836:in `render\_with\_no\_layout’  
/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
layout.rb:262:in `render_without_benchmark' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ benchmarking.rb:51:in `render’  
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ benchmarking.rb:51:in `render’  
/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
base.rb:1153:in `default_render' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ base.rb:1159:in `perform\_action\_without\_filters’  
/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
filters.rb:697:in `call_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ filters.rb:689:in `perform\_action\_without\_benchmark’  
/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
benchmarking.rb:68:in `perform_action_without_rescue' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure’  
/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
benchmarking.rb:68:in `perform_action_without_rescue' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ rescue.rb:199:in `perform\_action\_without\_caching’  
/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
caching.rb:678:in `perform_action' /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ connection_adapters/abstract/query_cache.rb:33:in `cache’  
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/  
query\_cache.rb:8:in `cache' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ caching.rb:677:in `perform\_action’  
/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
base.rb:524:in `send' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ base.rb:524:in `process\_without\_filters’  
/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
filters.rb:685:in `process_without_session_management_support' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ session_management.rb:123:in `process’  
/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
base.rb:388:in `process' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ dispatcher.rb:171:in `handle\_request’  
/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
dispatcher.rb:115:in `dispatch' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ dispatcher.rb:126:in `dispatch\_cgi’  
/usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
dispatcher.rb:9:in `dispatch' /usr/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb: 112:in `handle\_dispatch’  
/usr/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick\_server.rb:  
78:in `service' /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service’  
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' /usr/lib/ruby/1.8/webrick/server.rb:173:in `start\_thread’  
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start' /usr/lib/ruby/1.8/webrick/server.rb:162:in `start\_thread’  
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start' /usr/lib/ruby/1.8/webrick/server.rb:92:in `each’  
/usr/lib/ruby/1.8/webrick/server.rb:92:in `start' /usr/lib/ruby/1.8/webrick/server.rb:23:in `start’  
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start' /usr/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb: 62:in `dispatch’  
/usr/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/  
webrick.rb:66  
/usr/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem_original_require' /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’  
/usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active\_support/  
dependencies.rb:496:in `require' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:342:in `new\_constants\_in’  
/usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active\_support/  
dependencies.rb:496:in `require' /usr/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem\_original\_require’  
/usr/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`require’  
script/server:3

Rendering /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/  
action\_controller/templates/rescues/layout.erb (internal\_server\_error)

# cat \_footer.html.erb

```
<div id="footer">
  <ul>
    <% if logged_in? %>
      <% if admin? %>
        <li><%= link_to 'admin'[], :controller => 'admin', :action

```

=\> ‘index’ %\>  
\<% end %\>

- \<%= link\_to ‘logout’[], logout\_path(:to =\>  
CGI.escape(request.request\_uri)) %\>
  
\<% else %\>  
- \<%= link\_to ‘join’[], signup\_path(:to =\>  
CGI.escape(request.request\_uri)) %\>
  
- \<%= link\_to ‘login’[], login\_path(:to =\>  
CGI.escape(request.request\_uri)) %\>
  
\<% end %\>  
- \<%= link\_to ‘terms of use’[], :controller =\>  
‘about’, :action =\> ‘terms’ %\>
  
- \<%= link\_to ‘privacy’[], :controller =\> ‘about’, :action  
=\> ‘privacy’ %\>

---

<div class="post-metadata">

**Author:** ![Mister\_Blood\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@Mister\_Blood\_R](https://www.ruby-forum.com/u/Mister_Blood_R)\
**Post date:** [April 17, 2008, 10:13pm UTC](https://www.ruby-forum.com/t/cant-handle-if-logged-in-when-running-for-the-first-time/135100/2 "2008-04-17T22:13:29Z")

</div>

> # cat \_footer.html.erb
> 
> ```
> <div id="footer">
> <ul>
> <% if logged_in? %>
> <% if admin? %>
> <li><%= link_to 'admin'[], :controller => 'admin', :action
> 
> ```
> 
> =\> ‘index’ %\>  
> \<% end %\>
> 
> - \<%= link\_to ‘logout’[], logout\_path(:to =\>  
> CGI.escape(request.request\_uri)) %\>
>   
> \<% else %\>  
> - \<%= link\_to ‘join’[], signup\_path(:to =\>  
> CGI.escape(request.request\_uri)) %\>
>   
> - \<%= link\_to ‘login’[], login\_path(:to =\>  
> CGI.escape(request.request\_uri)) %\>
>   
> \<% end %\>  
> - \<%= link\_to ‘terms of use’[], :controller =\>  
> ‘about’, :action =\> ‘terms’ %\>
>   
> - \<%= link\_to ‘privacy’[], :controller =\> ‘about’, :action  
> =\> ‘privacy’ %\>

I’m looking at the above code and what I see if an internal server error  
and the beginnings of an \<% if . . .%\> and then an \<% end %\> but then  
after that I see and \<% else %\> that is not matched to any \<% if. . .%\>.  
My guess is that you don’t want that \<% end %\> in there.

-S

---

<div class="post-metadata">

**Author:** ![Mister\_Blood\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@Mister\_Blood\_R](https://www.ruby-forum.com/u/Mister_Blood_R)\
**Post date:** [April 17, 2008, 10:31pm UTC](https://www.ruby-forum.com/t/cant-handle-if-logged-in-when-running-for-the-first-time/135100/3 "2008-04-17T22:31:32Z")

</div>

> I’m looking at the above code and what I see if an internal server error  
> and the beginnings of an \<% if . . .%\> and then an \<% end %\> but then  
> after that I see and \<% else %\> that is not matched to any \<% if. . .%\>.  
> My guess is that you don’t want that \<% end %\> in there.
> 
> -S

What about the \<% if admin? %\> ?

---

<div class="post-metadata">

**Author:** ![Mister\_Blood\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@Mister\_Blood\_R](https://www.ruby-forum.com/u/Mister_Blood_R)\
**Post date:** [April 18, 2008, 2:59pm UTC](https://www.ruby-forum.com/t/cant-handle-if-logged-in-when-running-for-the-first-time/135100/4 "2008-04-18T14:59:52Z")

</div>

@Rails:

Have you patched authenticated\_system at all? My guess would be that  
either:

- You patched authenticated\_system to refer to Site
- Your current\_user refers to Site (or, if you’re added a NullUser  
form when there is no one matching authentication then it does).

A require in authenticated\_system or (null\_)user should do the trick.

Also, if this is truly a once-in-an-installation problem, then why not  
consider having your create\_user\_table migration create an admin/  
superadmin user with a default password?

On Apr 17, 4:57 pm, Shandy N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Mister\_Blood\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@Mister\_Blood\_R](https://www.ruby-forum.com/u/Mister_Blood_R)\
**Post date:** [April 20, 2008, 10:39am UTC](https://www.ruby-forum.com/t/cant-handle-if-logged-in-when-running-for-the-first-time/135100/5 "2008-04-20T10:39:13Z")

</div>

Thanks a LOT guys these were all supergreat suggestions!! 🙂

---

<div class="post-metadata">

**Author:** ![Mister\_Blood\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@Mister\_Blood\_R](https://www.ruby-forum.com/u/Mister_Blood_R)\
**Post date:** [April 17, 2008, 10:57pm UTC](https://www.ruby-forum.com/t/cant-handle-if-logged-in-when-running-for-the-first-time/135100/6 "2008-04-17T22:57:43Z")

</div>

Chris D. wrote:

> > I’m looking at the above code and what I see if an internal server error  
> > and the beginnings of an \<% if . . .%\> and then an \<% end %\> but then  
> > after that I see and \<% else %\> that is not matched to any \<% if. . .%\>.  
> > My guess is that you don’t want that \<% end %\> in there.
> > 
> > -S
> 
> What about the \<% if admin? %\> ?

Your right I didn’t see that. I might have miss led you. Just out of  
curiosity what does that logged\_in? method do? Is that a method you  
wrote? From that error that looks like where you problem is originating  
from.

> ActionView::TemplateError (Site::UndefinedError) on line #3 of layouts/  
> \_footer.html.erb:  
> 1:
> 
>   
> 2: 
>   
> 3: \<% if logged\_in? %\>
