Reputation: 197
Update I solved it. There were some issues with the if statements in the code
Everything works fine locally but I'm not sure why I'm getting errors
I have my rails app and I'm trying to access URL "/users/username" such as tbrown for example. Is it caused just by the undefined method "admin" or something else? Admin_user is already defined in my application_controller.rb and I have a admin_user.rb model. Post here are the heroku logs and the controller
heroku logs
2013-03-20T08:05:55+00:00 app[web.1]: Started GET "/users/tbrown" for xx.xx.xx
.xx at 2013-03-20 08:05:55 +0000
2013-03-20T08:05:55+00:00 app[web.1]:
2013-03-20T08:05:56+00:00 app[web.1]:
2013-03-20T08:05:56+00:00 app[web.1]: 22: <% end %></div>
2013-03-20T08:05:56+00:00 app[web.1]: ActionView::Template::Error (undefined met
hod `admin?' for nil:NilClass):
2013-03-20T08:05:56+00:00 app[web.1]: 23: <% if current_user.admin? %>
2013-03-20T08:05:56+00:00 app[web.1]: 21: <span class="content2"><%= com
ment.comment_content %></span>
2013-03-20T08:05:56+00:00 app[web.1]: 24: <%= link_to "delete", pos
t, method: :delete,
application_controller
def admin_user?
unless current_user && current_user.admin?
redirect_to root_url
return false
end
end
Upvotes: 0
Views: 668
Reputation: 15736
The problem is in your app/views/posts/_post.html.erb
view on line:
<% if current_user.admin? %>
This assumes that current_user is not nil (i.e. a user is logged in). You are already defensively coding around that problem in your controller admin_user?
method. It might be better to implement a helper method along the same lines (but without the redirect) and call that from your view instead.
Upvotes: 2