Closed beisert1 closed 10 years ago
You have nothing in def new. I don't see a point to the session model other than I'm sure you used it to create a table, hence you don't need to have that with has_secure_password. I don't see why that error is popping up. So hopefully the prior stated might somehow magically fix it.
rake db:drop rake db:create rake db:migrate may fix your tables issue as stated in a much earlier post by a very nice gaslight guy. (this will drop all your information in the tables and may require you to clear your cookies)
And you compare the tables to each other. Something like this in your view. <% if current_user && current_user.id == user.id %>
with something like this in your application_controller.rb
def current_user @current_user ||= User.find(session[:user_id]) if session[:user_id] end helper_method :current_user
Hope this helps.
It found an unexpected keyword end in user.rb, it was expecting end_of_input instead. That just means that you have an extra end in there after the interpreter thought the file was done. When you were copy-pasting from the guide into your user class you picked up an extra end and it's causing a SyntaxError.
Thanks guys! but I don't think its a missing end or an extra one I thoroughly checked for that because that was my first guess. I tried dropping my table earlier for users but I kept getting an error when trying to migrate
Can you paste the code from your UsersController?
class UsersController < ApplicationController
def new
end
def show
@user = User.find(params[:id])
end
def create
@user = User.new(user_params)
@user.save
flash[:notice] = "student was successfully created."
redirect_to @user, notice: "student was successfully created."
user = User.find_by_email(params[:email])
if user && user.authenticate(params[:password])
session[:user_id] = user.id
redirect_to admin_root_path, :notice => "Welcome back, #{user.email}"
else
flash.now.alert = "Invalid email or password"
render "new"
end
end
def index
@users = User.all
end
def edit
@user = User.find(params[:id])
end
def update
@user = User.find(params[:id])
if @user.update(params[:user].permit(:name, :nickname, :email, :image))
flash[:notice] = "You have successfully updated your profile."
redirect_to @user, notice: "You have successfully updated your profile."
else
render 'edit'
end
end
def destroy
@user = User.find(params[:id])
@user.destroy
redirect_to users_path
end
private
def user_params
params.require(:user).permit(:name, :nickname, :email, :image)
end
end
Not sure if this helps but there is a small difference I see. All of your other definitions are using @user while your def index is using the plural version @users. Something to consider / try
Looks like your trying to do too much in your create action.
Have a look at http://railscasts.com/episodes/270-authentication-in-rails-3-1
As for the error, there's something wrong in User.rb
. As @jaimerump said, it's probably an unmatched end
I cant believe I missed it!! you guys are right! I had an extra end in my user.rb file!!!
Thanks everyone :+1:
Here is the error I get after adding the following this guide to implement has_secure_password
http://www.millwoodonline.co.uk/blog/using-hassecurepassword-for-rails-authentication
After adding all the code I am unable to update my db migrate with users table so I create a new one for sessions but I added the code from the guide in both my users model, users controller and the schema users table. As well as created a sessions model. sessions controller, and updated my sessions table successfully however, I get this following error, and I dont know how to link the user and session tables together?