Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 Rails 3:修改现有sqlite db后的未定义方法_Ruby On Rails 3_Sqlite_Methods_Undefined_Rails Console - Fatal编程技术网

Ruby on rails 3 Rails 3:修改现有sqlite db后的未定义方法

Ruby on rails 3 Rails 3:修改现有sqlite db后的未定义方法,ruby-on-rails-3,sqlite,methods,undefined,rails-console,Ruby On Rails 3,Sqlite,Methods,Undefined,Rails Console,在rails控制台中,执行User.first和Post.first很好。user工作正常,但user.first.posts给了我一个未定义的方法错误 模型: class User < ActiveRecord::Base attr_accessible :role :user_email, :user_name has_many :posts end class用户用户模型有:role和I>会假设任何基于用户的应用程序都有很多依赖项,因此会像我的一样失败 。。。还是

在rails控制台中,执行User.first和Post.first很好。user工作正常,但user.first.posts给了我一个未定义的方法错误

模型:

class User < ActiveRecord::Base
    attr_accessible :role :user_email, :user_name

    has_many :posts
end
class用户

class Post
当我创建一个新项目时,一切都很好,但在这种情况下,我做了一些不同的事情。我将现有数据库(sqlite)从另一个web应用程序(非rails)改编为rails。我所做的是重命名列以符合rails约定,以前我使用用户名作为唯一键并使用该键链接到帖子所有者,我将列名更改为user_id,并将所有值更新为相关用户id。我还将列类型和值更改为int值

Comment也是如此:Comment.first.post有效,但post.commments给出了未定义的方法错误

在执行User.joins(:post(s))时,我得到错误“未找到名为'posts'的关联”,但post.joins(:User)工作正常

编辑:
真可耻——我遗漏了我认为不相关的相关信息

无论如何,我有一个名为role的专栏,因此用户模型有attr_可访问性:role---one>我删除了所有按预期工作的内容

然而,我不明白为什么这会产生影响。这个:>用户模型有:role和I>会假设任何基于用户的应用程序都有很多依赖项,因此会像我的一样失败

。。。还是我还遗漏了什么


您也更改了表名吗?添加了@MurifoX,特别是Post->postsys,表名是posts。我基本上在一个普通应用程序中为所有模型运行generate,然后重命名旧数据库中的表和列以匹配生成的数据库中的所有内容,然后重命名数据库文件。真丢脸——我遗漏了我认为不相关的相关信息。无论如何,我有一个名为role的专栏,所以用户模型有attr_可访问:role--一旦我删除了,一切都按预期进行。然而,我不明白为什么这会产生影响。这个:用户模型有:角色,我认为任何基于用户的应用都会有很多依赖性,因此会像我的一样失败。。。还是我还遗漏了什么?
class Post < ActiveRecord::Base
    attr_accessible :content, :status, :title, :user_id

    belongs_to :user
    has_many :comments
end