浏览 179 次
|
该帖已经被评为新手帖
|
|
|---|---|
| 作者 | 正文 |
|
最后更新时间:2008-07-07
我有两个模型,user和profile.
user是在restful authentication里面生成的,profile是user的子类,他两个的关系是user has_one profile user.rb内代码是:
has_one :profile attr_accessible :login, :email, :password, :password_confirmation profile.rb代码是:
class Profile < ActiveRecord::Base belongs_to :user attr_accessible :name, :gender, :birthday, :place, :about_me end 在profile_controller.rb内代码是:
class ProfilesController < ApplicationController
before_filter :login_required
def edit
@user = User.find(current_user)
@profile = Profile.find(params[:user_id])
end
def update
@user = User.find(current_user)
@profile = @user.profile
if @profile.update_attributes(@profile.attributes)
flash[:notice] = "Your profile was successfully updated"
redirect_to(user_path(@user))
else
render :action => 'edit'
end
end
end
但是,我在进行更新profile的时候,log出现错误说:
WARNING: Can't mass-assign these protected attributes: updated_at, id, user_id, created_at
但是,这里我已经把attr_accessible申明了啊?
怎么解决这个问题呢? 声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
|
| 返回顶楼 | |
|
最后更新时间:2008-07-07
你申明的attr_accessible里面并没有user_id, id之类的属性...
|
|
| 返回顶楼 | |
|
最后更新时间:2008-07-07
Readonly 写道 你申明的attr_accessible里面并没有user_id, id之类的属性...
如果申明,岂不是能够更改id了? 而且,我声明了也不管用…… |
|
| 返回顶楼 | |
|
最后更新时间:2008-07-07
可是你赋值的时候给了这些参数,当然会报警告了
|
|
| 返回顶楼 | |
|
最后更新时间:2008-07-07
那我应该在提交表单里面避免掉这几个字段对吗?
|
|
| 返回顶楼 | |




