Can't handle <% if logged_in? %> when running for the first time

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]
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’ %>


  • 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

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

    @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. [email protected]

    Thanks a LOT guys these were all supergreat suggestions!! :slight_smile:

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