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

**URL:** <https://discuss.rubyonrails.org/t/cant-handle-if-logged-in-when-running-for-the-first-time/28177>\
**Category:** rubyonrails-talk\
**Created:** [April 17, 2008, 7:49pm UTC](https://discuss.rubyonrails.org/t/cant-handle-if-logged-in-when-running-for-the-first-time/28177 "2008-04-17T19:49:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mister\_Blood\_Rails](https://avatars.discourse-cdn.com/v4/letter/m/e19b73/32.png) [@Mister\_Blood\_Rails](https://discuss.rubyonrails.org/u/Mister_Blood_Rails)\
**Post date:** [April 17, 2008, 7:49pm UTC](https://discuss.rubyonrails.org/t/cant-handle-if-logged-in-when-running-for-the-first-time/28177/1 "2008-04-17T19:49:50Z")

</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.

Processing MainController#index (for 127.0.0.1 at 2008-04-14 01:30:13) [GET] &nbsp;&nbsp;Session ID: BAh7CjoMY3NyZl9pZCIlYTNiMmY5ZDFmMjJhOWJhZDhhMTI1YzQxYzkzNDI5%0ANzg6CnRpdGxlewA6CXVzZXJpBjoOcmV0dXJuX3RvMCIKZmxhc2hJQzonQWN0%0AaW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA %3D%3D--346cfed42d9b4cc6e1dfc4f4d95ae774e5e9dc48 &nbsp;&nbsp;Parameters: {"action"=\>"index", "controller"=\>"main"} &nbsp;&nbsp;ParentCategory Load (0.002000) SELECT \* FROM `parent_categories` ORDER BY name ASC &nbsp;&nbsp;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) &nbsp;&nbsp;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: \<div id="footer"\> 2: \<ul\> 3: \<% if logged\_in? %\> 4: \<% if admin? %\> 5: \<li\>\<%= link\_to 'admin', admin\_path %\>\</li\> 6: \<% end %\> 7: \<li\>\<%= link\_to 'logout', logout\_path(:to =\> CGI.escape(request.request\_uri)) %\>\</li\>

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

&nbsp;&nbsp;&nbsp;&nbsp;\<div id="footer"\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<ul\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% if logged\_in? %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% if admin? %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<li\>\<%= link\_to 'admin', :controller =\> 'admin', :action =\> 'index' %\>\</li\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% end %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<li\>\<%= link\_to 'logout', logout\_path(:to =\> CGI.escape(request.request\_uri)) %\>\</li\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% else %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<li\>\<%= link\_to 'join', signup\_path(:to =\> CGI.escape(request.request\_uri)) %\>\</li\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<li\>\<%= link\_to 'login', login\_path(:to =\> CGI.escape(request.request\_uri)) %\>\</li\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% end %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<li\>\<%= link\_to 'terms of use', :controller =\> 'about', :action =\> 'terms' %\>\</li\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<li\>\<%= link\_to 'privacy', :controller =\> 'about', :action =\> 'privacy' %\>\</li\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</ul\> &nbsp;&nbsp;&nbsp;&nbsp;\</div\> &nbsp;&nbsp;\</body\> \</html\>

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [April 17, 2008, 8:13pm UTC](https://discuss.rubyonrails.org/t/cant-handle-if-logged-in-when-running-for-the-first-time/28177/2 "2008-04-17T20:13:29Z")

</div>

> # cat \_footer.html.erb
> 
> &nbsp;&nbsp;&nbsp;&nbsp;\<div id="footer"\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<ul\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% if logged\_in? %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% if admin? %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<li\>\<%= link\_to 'admin', :controller =\> 'admin', :action =\> 'index' %\>\</li\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% end %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<li\>\<%= link\_to 'logout', logout\_path(:to =\> CGI.escape(request.request\_uri)) %\>\</li\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% else %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<li\>\<%= link\_to 'join', signup\_path(:to =\> CGI.escape(request.request\_uri)) %\>\</li\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<li\>\<%= link\_to 'login', login\_path(:to =\> CGI.escape(request.request\_uri)) %\>\</li\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% end %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<li\>\<%= link\_to 'terms of use', :controller =\> 'about', :action =\> 'terms' %\>\</li\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<li\>\<%= link\_to 'privacy', :controller =\> 'about', :action =\> 'privacy' %\>\</li\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</ul\> &nbsp;&nbsp;&nbsp;&nbsp;\</div\> &nbsp;&nbsp;\</body\> \</html\>

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:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [April 17, 2008, 8:57pm UTC](https://discuss.rubyonrails.org/t/cant-handle-if-logged-in-when-running-for-the-first-time/28177/3 "2008-04-17T20:57:43Z")

</div>

Chris Dekker 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.

---

<div class="post-metadata">

**Author:** ![AndyV](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@AndyV](https://discuss.rubyonrails.org/u/AndyV)\
**Post date:** [April 18, 2008, 12:58pm UTC](https://discuss.rubyonrails.org/t/cant-handle-if-logged-in-when-running-for-the-first-time/28177/4 "2008-04-18T12:58:45Z")

</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?

---

<div class="post-metadata">

**Author:** ![Mister\_Blood\_Rails](https://avatars.discourse-cdn.com/v4/letter/m/e19b73/32.png) [@Mister\_Blood\_Rails](https://discuss.rubyonrails.org/u/Mister_Blood_Rails)\
**Post date:** [April 20, 2008, 8:38am UTC](https://discuss.rubyonrails.org/t/cant-handle-if-logged-in-when-running-for-the-first-time/28177/5 "2008-04-20T08:38:24Z")

</div>

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