耙子没有返回任何东西

时间:2011-01-07 19:43:03

标签: ruby-on-rails

我创建了一个rails应用程序。我使用

 ruby script/generate model Article

创建了一个模型

接下来我通过在self.up方法中添加这些行来编辑我的001_create_articles.rb文件

 def self.up
    create_table :articles do |t|
        t.string :title
        t.text :body
        t.string :published_at

    t.timestamps
end

end

现在我跑了
{{1}}
。但迁移不起作用,它根本不打印任何东西。谁知道我哪里出错?

2 个答案:

答案 0 :(得分:0)

您是否从您的up方法中遗漏了一个end

def self.up
  create_table :articles do |t|
    t.string :title
    t.text :body
    t.string :published_at
    t.timestamps
  end
end

答案 1 :(得分:0)

我认为您必须生成迁移。如果我理解正确,您将迁移代码添加到模型中。

你必须运行类似的东西:

ruby script/generate migration articles

之后打开生成的文件并在那里添加代码。希望它有所帮助

相关问题