link requires id but is nil when signed out and created error
I have a nav bar that appears on every page of my website. There is a link
in the navbar like this:
<%= link_to 'Publish' , new_user_comic_title_path(user_id:
current_user.id) %>
I am using the DEVISE gem. Each user has many Comic_titles, which is why I
have the new_user_comic_title_path. The problem is, when the user is
signed out, current_user.id = nil. The error is below:
Called id for nil, which would mistakenly be 4 -- if you really wanted the
id of nil, use object_id
I would like (1) the page to render without it throwing this error and (2)
if the link is clicked and the user is not signed it, it redirects to the
sign in page.
Really appreciate the help!
No comments:
Post a Comment