Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

current_user helper method error #164

Closed
AjayBarot opened this issue Feb 4, 2014 · 0 comments
Closed

current_user helper method error #164

AjayBarot opened this issue Feb 4, 2014 · 0 comments

Comments

@AjayBarot
Copy link

hi i m using rails 4 and i have this error shows in current_user helper method .

ActiveRecord::RecordNotFound in UsersController#new
Couldn't find User without an ID
and My code for pplication_controller.rb:
def current_user
@current_user ||= User.find(session[:user_id]) if session [:user_id]
end
and this is my code of user_controller.rb:
def new
@user= User.new
end
def create
@user= User.new(params[:user])
if @user.save
redirect_to root_url, :notice => "Signed up!"
else
render "new"
end
end
and now this is my code for application.html.erb where i check current_user:

<% if current_user %> Logged in as <%= current_user.email %>, <%= link_to "Log out", log_out_path %> <% else %> <%= link_to "Sign up", sign_up_path %> <%= link_to "log in", log_in_path %> <% end -%>

Screenshot
screenshot from 2014-02-04 20 00 04
screenshot from 2014-02-04 20 00 24
screenshot from 2014-02-04 20 00 58
screenshot from 2014-02-04 20 01 19

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@AjayBarot and others