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
会话助手中的代码:
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
我正在使用此代码,
但我无法在数据库中编辑和更新我的详细信息。
因为我对此非常陌生,
需要别人的帮助。
提前致谢....
答案 0 :(得分:1)
您是否已将SessionHelper模块包含在控制器中?
从您的示例代码中,我假设您正在使用Michael Hartl的 RailsTutorial 。您必须在ApplicationController中包含SessionsHelper才能在所有控制器中使用它。查看书中的清单8.14:
class ApplicationController < ActionController::Base
protect_from_forgery
include SessionsHelper
# Force signout to prevent CSRF attacks
def handle_unverified_request
sign_out
super
end
end