0

I just created an admin profile for my app on Heroku. I did this by going into my Heroku production database with pgAdminIII as described here, in the database I simply changed the admin field for my user profile to true.

It worked in so far as now I have admin access throughout most of the app but when I try to view my admin profile on the app I get the error We're sorry, but something went wrong. When I log in with a normal user profile I can still view that profile easily.

The heroku logs are saying there is an undefined method 'name', but I don't understand this error as it is not showing when I try to access other profiles in my production environment or anywhere in my development environment.

I do have a if current_user.try(:admin?) condition in my users/show.html.erb but this is not throwing back any errors in my development environment.

I'm not sure what is going wrong here, I'm new to web development, is it poor practice to go through pgAdmin to edit the production database? It seems to have thrown a spanner in the works.

Heroku Logs for admin profile GET

2013-04-19T14:06:10.911478+00:00 app[web.1]: => Booting WEBrick
2013-04-19T14:06:10.911478+00:00 app[web.1]: => Rails 3.2.12 application starting in production on http://0.0.0.0:54611
2013-04-19T14:06:10.911478+00:00 app[web.1]: => Call with -d to detach
2013-04-19T14:06:10.911478+00:00 app[web.1]: => Ctrl-C to shutdown server
2013-04-19T14:06:10.911478+00:00 app[web.1]: Started GET "/users/1" for 86.47.2.244 at 2013-04-19 14:06:10 +0000
2013-04-19T14:06:11.037505+00:00 app[web.1]: Processing by UsersController#show as HTML
2013-04-19T14:06:11.037505+00:00 app[web.1]:   Parameters: {"id"=>"1"}
2013-04-19T14:06:11.439430+00:00 app[web.1]: Completed 500 Internal Server Error in 402ms
2013-04-19T14:06:11.441222+00:00 app[web.1]: ActionView::Template::Error (undefined method `name' for nil:NilClass):
2013-04-19T14:06:11.441222+00:00 app[web.1]:     28:           <tr>
2013-04-19T14:06:11.441222+00:00 app[web.1]:     29:           <% @user.photos.each do |photo| %>
2013-04-19T14:06:11.441222+00:00 app[web.1]:     30:             <td class='user_pics'>
2013-04-19T14:06:11.439430+00:00 app[web.1]:   Rendered users/show.html.erb within layouts/application (283.4ms)
2013-04-19T14:06:11.441222+00:00 app[web.1]:     33:               <%= link_to t('.destroy', :default => t("helpers.links.destroy")), photo_path(photo),:method => :delete, :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },:class => 'btn btn-mini btn-danger' %>
2013-04-19T14:06:11.441222+00:00 app[web.1]:     34:             </td>
2013-04-19T14:06:11.441222+00:00 app[web.1]: 
2013-04-19T14:06:11.441222+00:00 app[web.1]:     31:               <h6><%= get_hike_name_by_photo(photo.hikingtrail_id) %></h6>
2013-04-19T14:06:11.441495+00:00 app[web.1]:   app/views/users/show.html.erb:31:in `block in _app_views_users_show_html_erb__1466921769571898123_36255720'
2013-04-19T14:06:11.441222+00:00 app[web.1]:   app/helpers/users_helper.rb:4:in `get_hike_name_by_photo'
2013-04-19T14:06:11.441222+00:00 app[web.1]:     32:               <%= image_tag photo.image_url(:thumb).to_s %> <br />
2013-04-19T14:06:11.441495+00:00 app[web.1]: 
2013-04-19T14:06:11.441495+00:00 app[web.1]:   app/views/users/show.html.erb:29:in `_app_views_users_show_html_erb__1466921769571898123_36255720'
2013-04-19T14:06:11.441495+00:00 app[web.1]: 
2013-04-19T14:06:11.445147+00:00 heroku[router]: at=info method=GET path=/users/1 host=hiking-project.herokuapp.com fwd="86.47.2.244" dyno=web.1 connect=1ms service=548ms status=500 bytes=643

Heroku Logs for non-admin profile GET

2013-04-19T14:07:42.861730+00:00 app[web.1]:   Parameters: {"id"=>"2"}
2013-04-19T14:07:42.857372+00:00 app[web.1]: Started GET "/users/2" for 86.47.2.244 at 2013-04-19 14:07:42 +0000
2013-04-19T14:07:42.861675+00:00 app[web.1]: Processing by UsersController#show as HTML
2013-04-19T14:07:42.889420+00:00 app[web.1]:   Rendered users/show.html.erb within layouts/application (24.2ms)
2013-04-19T14:07:42.900768+00:00 app[web.1]:   Rendered layouts/_navbar.html.erb (2.2ms)
2013-04-19T14:07:42.901987+00:00 app[web.1]: Completed 200 OK in 40ms (Views: 28.3ms | ActiveRecord: 11.0ms)
2013-04-19T14:07:42.901785+00:00 app[web.1]:   Rendered layouts/_footer.html.erb (0.6ms)
2013-04-19T14:07:42.905317+00:00 heroku[router]: at=info method=GET path=/users/2 host=hiking-project.herokuapp.com fwd="86.47.2.244" dyno=web.1 connect=1ms service=53ms status=200 bytes=6621
2013-04-19T14:07:43.100688+00:00 heroku[router]: at=info method=GET path=/assets/application-5343b16e766707937994ff5eeed67d4a.css host=hiking-project.herokuapp.com fwd="86.47.2.244" dyno=web.1 connect=2ms service=6ms status=304 bytes=0
2013-04-19T14:07:43.209119+00:00 heroku[router]: at=info method=GET path=/assets/application-2f6741be57170d2a4f223dd28b4827c8.js host=hiking-project.herokuapp.com fwd="86.47.2.244" dyno=web.1 connect=0ms service=4ms status=304 bytes=0
2013-04-19T14:07:43.263057+00:00 heroku[router]: at=info method=GET path=/uploads/photo/image/12/thumb_View_from_spink.jpg host=hiking-project.herokuapp.com fwd="86.47.2.244" dyno=web.1 connect=0ms service=25ms status=404 bytes=728
2013-04-19T14:07:43.256301+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/uploads/photo/image/11/thumb_spink_sleepers.jpg"):
2013-04-19T14:07:43.256301+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/rack/logger.rb:32:in `call_app'
2013-04-19T14:07:43.256301+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
2013-04-19T14:07:43.256301+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/rack/logger.rb:16:in `block in call'
2013-04-19T14:07:43.256566+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:479:in `call'
2013-04-19T14:07:43.261546+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/lock.rb:15:in `call'
2013-04-19T14:07:43.261546+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/static.rb:62:in `call'
2013-04-19T14:07:43.256817+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/content_length.rb:14:in `call'
2013-04-19T14:07:43.256817+00:00 app[web.1]:   /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
2013-04-19T14:07:43.256817+00:00 app[web.1]:   /usr/local/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
2013-04-19T14:07:43.261546+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:136:in `forward'
2013-04-19T14:07:43.261546+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:245:in `fetch'
2013-04-19T14:07:43.261546+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:185:in `lookup'
2013-04-19T14:07:43.261546+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
2013-04-19T14:07:43.256566+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/lock.rb:15:in `call'
2013-04-19T14:07:43.256566+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:136:in `forward'
2013-04-19T14:07:43.256566+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:66:in `call!'
2013-04-19T14:07:43.261546+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:66:in `call!'
2013-04-19T14:07:43.261546+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:51:in `call'
2013-04-19T14:07:43.261546+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:479:in `call'
2013-04-19T14:07:43.261295+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/tagged_logging.rb:22:in `tagged'
2013-04-19T14:07:43.256301+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
2013-04-19T14:07:43.261295+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/rack/logger.rb:32:in `call_app'
2013-04-19T14:07:43.256301+00:00 app[web.1]: 
2013-04-19T14:07:43.261755+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/application.rb:223:in `call'
2013-04-19T14:07:43.261755+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/content_length.rb:14:in `call'
2013-04-19T14:07:43.261755+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/rack/log_tailer.rb:17:in `call'
2013-04-19T14:07:43.261295+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/rack/logger.rb:16:in `call'
2013-04-19T14:07:43.256301+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/tagged_logging.rb:22:in `tagged'
2013-04-19T14:07:43.256301+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/rack/logger.rb:16:in `call'
2013-04-19T14:07:43.256817+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/handler/webrick.rb:59:in `service'
2013-04-19T14:07:43.261755+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/handler/webrick.rb:59:in `service'
2013-04-19T14:07:43.261
755+00:00 app[web.1]:   /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
2013-04-19T14:07:43.261295+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/rack/logger.rb:16:in `block in call'
2013-04-19T14:07:43.256301+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/methodoverride.rb:21:in `call'
2013-04-19T14:07:43.256817+00:00 app[web.1]: 
2013-04-19T14:07:43.261755+00:00 app[web.1]:   /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
2013-04-19T14:07:43.261755+00:00 app[web.1]:   /usr/local/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
2013-04-19T14:07:43.256566+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/runtime.rb:17:in `call'
2013-04-19T14:07:43.248790+00:00 app[web.1]: Started GET "/uploads/photo/image/11/thumb_spink_sleepers.jpg" for 86.47.2.244 at 2013-04-19 14:07:43 +0000
2013-04-19T14:07:43.256817+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/rack/log_tailer.rb:17:in `call'
2013-04-19T14:07:43.261295+00:00 app[web.1]: 
2013-04-19T14:07:43.261295+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
2013-04-19T14:07:43.256817+00:00 app[web.1]: 
2013-04-19T14:07:43.258182+00:00 app[web.1]: Started GET "/uploads/photo/image/12/thumb_View_from_spink.jpg" for 86.47.2.244 at 2013-04-19 14:07:43 +0000
2013-04-19T14:07:43.261295+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/request_id.rb:22:in `call'
2013-04-19T14:07:43.261295+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/uploads/photo/image/12/thumb_View_from_spink.jpg"):
2013-04-19T14:07:43.261295+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
2013-04-19T14:07:43.261295+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/methodoverride.rb:21:in `call'
2013-04-19T14:07:43.256301+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/request_id.rb:22:in `call'
2013-04-19T14:07:43.256566+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/static.rb:62:in `call'
2013-04-19T14:07:43.261755+00:00 app[web.1]: 
2013-04-19T14:07:43.261755+00:00 app[web.1]: 
2013-04-19T14:07:43.256566+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:245:in `fetch'
2013-04-19T14:07:43.256817+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/application.rb:223:in `call'
2013-04-19T14:07:43.256817+00:00 app[web.1]:   /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
2013-04-19T14:07:43.261546+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/runtime.rb:17:in `call'
2013-04-19T14:07:43.256566+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
2013-04-19T14:07:43.256566+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:185:in `lookup'
2013-04-19T14:07:43.256566+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:51:in `call'
2013-04-19T14:07:43.257395+00:00 heroku[router]: at=info method=GET path=/uploads/photo/image/11/thumb_spink_sleepers.jpg host=hiking-project.herokuapp.com fwd="86.47.2.244" dyno=web.1 connect=0ms service=12ms status=404 bytes=728

users/show.html.erb

<div class="page-header">
  <h1 class='float_left'>Your Profile</h1>
  <%= link_to "Edit your Profile", edit_user_path(current_user), :class => 'btn btn-primary float_right' %>
  <div class='clear_float'></div>
</div>


<p>
  <b>username:</b>
  <%= @user.user_name %>
</p>

<p>
  <b>email:</b>
  <%= @user.email %>
</p>

<div class="accordion" id="accordion2">
  <div class="accordion-group">
    <div class="accordion-heading">
      <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
        Your Photos
      </a>
    </div>
    <div id="collapseOne" class="accordion-body collapse in">
      <div class="accordion-inner">
        <table>
          <tr>
          <% @user.photos.each do |photo| %>
            <td class='user_pics'>
              <h6><%= get_hike_name_by_photo(photo.hikingtrail_id) %></h6>
              <%= image_tag photo.image_url(:thumb).to_s %> <br />
              <%= link_to t('.destroy', :default => t("helpers.links.destroy")), photo_path(photo),:method => :delete, :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },:class => 'btn btn-mini btn-danger' %>
            </td>
          <% end %>
          </tr>
        </table>
      </div>
    </div>
  </div>

    <div class="accordion-group">
    <div class="accordion-heading">
      <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">
        Hikes You Created
      </a>
    </div>
    <div id="collapseTwo" class="accordion-body collapse">
      <div class="accordion-inner">
       <table class="table table-striped">
          <thead>
            <tr>
              <th>Name</th>
              <th>Brief Description</th>
              <th style="min-width:120px;">Location</th>
              <th>Country</th>
              <th>Looped</th>
              <th style="min-width:100px;">Duration</th>
              <th></th>
              <th></th>
              <th></th>
            </tr>
          </thead>
          <tbody>
        <% @user.hikingtrails.each do |hikingtrail| %><tr>
            <tr>
                <td><%= link_to hikingtrail.name, hikingtrail_path(hikingtrail) %></td>
                <td><%= truncate(hikingtrail.description, :length => 95, :separator => ' ') %></td>
                <!-- <td><%= hikingtrail.description %></td> -->
                <td><%= hikingtrail.addr_2.capitalize %>, <%= hikingtrail.addr_3.capitalize %></td>
                <td><%= hikingtrail.country %></td>
                <td><%= boolean_to_yes_or_no(hikingtrail.looped) %></td>
                <td><%= hikingtrail.duration_hours %>hrs <%= hikingtrail.duration_mins %>mins</td>
                <td>
                  <%= link_to t('.edit', :default => t("helpers.links.edit")),edit_hikingtrail_path(hikingtrail), :class => 'btn btn-mini' %>
                  <% if current_user.try(:admin?) %>
                  <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
                              hikingtrail_path(hikingtrail),
                              :method => :delete,
                              :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
                              :class => 'btn btn-mini btn-danger' %>
                  <% end %>
                </td>
              </tr>
            <% end %>
          </tbody>
        </table>
      </div>
    </div>
  </div>
Community
  • 1
  • 1
Holly
  • 7,462
  • 23
  • 86
  • 140

1 Answers1

1

Does every hikingtrail have a name value in it? When you get a NilClass error, that means you're trying to call something that isn't there. In this case undefined method 'name' for nil:NilClass means you're asking for a name that isn't in the database. Check this line:

<td><%= link_to hikingtrail.name, hikingtrail_path(hikingtrail) %></td>

and change it to:

<td><%= link_to hikingtrail.name, hikingtrail_path(hikingtrail) if hikingtrail.name.present? %></td>
bcackerman
  • 1,486
  • 2
  • 22
  • 36
  • thanks bcackerman, I did think of that but each `hikingtrail` must have a name, I set up validation rule for it. – Holly Apr 19 '13 at 15:58