Ruby on Rails未定义的方法`attr_accessible'和'before_save'? [英] Ruby on Rails undefined method `attr_accessible' and 'before_save'?

查看:207
本文介绍了Ruby on Rails未定义的方法`attr_accessible'和'before_save'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始了一个新的RoR项目,并从大约6个月前复制了一些旧的代码。



由于某些原因,我收到以下错误在我的用户模型中:

 未定义的方法attr_accessible为用户:类
/ pre>

当我评论attr_accessible行时,我在同一个文件中收到类似的错误:

 未定义的方法`before_save'为用户:类

我评论说,我得到另一个:

  undefined方法验证为用户:类

为什么attr_accessible和before_save是未定义的方法?我认为那些内置于Ruby on Rails!?

解决方案

你的User类是否继承自ActiveRecord :: Base? p>

应该如下所示:

  class User< ActiveRecord :: Base 


I recently started a new RoR project, and copied some of my old code from about 6 months ago.

For some reason, I'm getting the following error in my User model:

undefined method `attr_accessible' for User:Class

When I comment the attr_accessible line out, I then get a similar error in the same file:

undefined method `before_save' for User:Class

And when I comment that out, I get another one:

undefined method `validates' for User:Class

Why would attr_accessible and before_save be undefined methods? I thought those were built in to Ruby on Rails!?

解决方案

Is your User class inheriting from ActiveRecord::Base?

It should look like this:

class User < ActiveRecord::Base

这篇关于Ruby on Rails未定义的方法`attr_accessible'和'before_save'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆