开发者

Update a String Attribute in Rails

I am trying to update a string attribute in the database.

I tried using update_attribute but it isn't working. It works for integer attributes but not for String attributes.

How do i solve this ?

EDIT

code example:

@post = Post.find(params[:post_id])
@comment = @post.comments.create!(para开发者_开发问答ms[:comment])
@comment.update_attribute(:commenter,User.find_by_id(session[:user_id]).name)


First off, is there any reason you save the name as a string in the database? Normally you would go through the association to get the name.

@comment.user.name

I would really suggest you add a user_id to the comments table and then use:

@comment.user = User.find_by_id(session[:user_id]) 

or

@comment.update_attribute(:user_id, session[:user_id])

to update the commenter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜