我的控制器显示方法中有@user = current_user
。但是当我在视图中使用由@user.email
创建时,它随着每次登录而变化,我希望它显示创建/进行编辑的用户。
那么如何将current_user保存到数据库中以便我可以显示进行编辑的相应用户?
更新:这是代码
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
has_many :groups
end
class Group < ActiveRecord::Base
belongs_to :user
end
t.has_many:群组
t.belongs_to :user
def create
@user = User.find(params[:id])
@group = @user.groups.build(params[:id])
respond_to do |format|
if @group.save
format.html { redirect_to @group, notice: 'Group was successfully created.' }
format.json { render json: @group, status: :created, location: @group }
else
format.html { render action: "new" }
format.json { render json: @group.errors, status: :unprocessable_entity }
end
end
end
def new
@user = User.find(params[:id])
@group = @user.groups.build(params[:id])
respond_to do |format|
format.html # new.html.erb
format.json { render json: @group }
end
end