Reputation: 1
class UsersController < ApplicationController
before_filter :signed_in_user, only: [:index, :edit, :update]
before_filter :correct_user, only: [:edit, :update]
private
def user_params
params.require(:user).permit(:name, :email, :password,:password_confirmation)
end
def signed_in_user
unless signed_in?
store_location
redirect_to signin_url, notice: "Please sign in."
end
end
def correct_user
@user = User.find(params[:id])
redirect_to(root_url) unless current_user?(@user)
end
end
code in session helper:
def sign_in(user)
remember_token = User.new_remember_token
cookies.permanent[:remember_token] = remember_token
user.update_attribute(:remember_token, User.encrypt(remember_token))
self.current_user = user
end
def signed_in?
!current_user.nil?
end
I am using this code,
But I am unable to edit and update my details in the database.
As I am extremely new to this,
Need someone help.
Thanks in Advance....
Upvotes: 0
Views: 328
Reputation: 1985
Have you included the SessionHelper module in your controller?
From your example code, I'm assuming you're using the RailsTutorial by Michael Hartl. You have to include the SessionsHelper in your ApplicationController to be able to use it in all controllers. Check out Listing 8.14 in the book:
class ApplicationController < ActionController::Base
protect_from_forgery
include SessionsHelper
# Force signout to prevent CSRF attacks
def handle_unverified_request
sign_out
super
end
end
Upvotes: 1