I have started building a simple rails app and have used Devise for authentication. I have created a Dashboard page for the users after they login, it’s using a users_contoller added below:
class UserController < ApplicationController
before_filter :authenticate_user!
def show
@user = User.find(params[:id])
end
end
I have renamed this user#show to dashboard in routes:
match '/dashboard', to: 'user#show'
I have created a if else statement in the User show html page to see if this works, shown below:
<% if @user.lists.any? %>
Cool you have lists
<% else %>
OK No Lists
<%= @user[:id] %>
<% end %>
Unfortunately this just renders an error when trying to load the page in a browser
Couldn't find User without an ID
Im not sure if this is simply a Devise setting or something more fundamental and apologies in advance if this is avery noob question.
When a user is autenticated using devise the current autenticated user is “stored” in a helper called “current_user”.
A quick fix for your problem should be changing the code in your “UserController” to something like this (at the same time mantaning the rest funcionality):