Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.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/1/vb.net/15.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 Rails ActveRecord在迁移后无法再找到行_Ruby On Rails_Activerecord - Fatal编程技术网

Ruby on rails Rails ActveRecord在迁移后无法再找到行

Ruby on rails Rails ActveRecord在迁移后无法再找到行,ruby-on-rails,activerecord,Ruby On Rails,Activerecord,有了这个控制器/视图,以前一切都很好 def testo @positions = Positions.find(:all) @comments = Comment.find(:all) respond_to do |format| format.html # new.html.erb end end 查看代码: .navcon.sprite-gear.sprite .notifications.ajaxapp .na_head NOTIFICATIONS

有了这个控制器/视图,以前一切都很好

def testo
  @positions = Positions.find(:all)
  @comments = Comment.find(:all)

  respond_to do |format|
    format.html # new.html.erb
  end
end
查看代码:

.navcon.sprite-gear.sprite
  .notifications.ajaxapp
    .na_head NOTIFICATIONS
      - @comments.each do |comment|
        .na_item
          .na_shell
我通过迁移向“Comments”表添加了一列,现在@Comments变量返回时未定义。有趣的是,这些代码都没有被更改,数据库中的所有记录仍然存在,(我可以在控制台中使用与控制器中使用的相同命令来获得它们)

class AddColumn
此处可以看到错误:
尝试将迁移更改为:

def change
   add_column :comments, :position, :text
end

我还建议为您的迁移提供一个更具描述性的名称(除非您为我们缩短它,而不是更重要的:)

签入rails控制台您是否可以通过键入“Commant.all”来查看这些记录?是的,它们都在控制台中随.all和with返回。find(:all)
@comments
应返回与
Comment.find(:all)相同的结果
在rails控制台中。。。将该错误的完整跟踪放在这里,以便我们进一步提供帮助……添加了一个指向该错误的链接,该错误可能是由sqlite3 gem而不是sqlite3 ruby引起的类似问题。我确实安装了普通sqlite3。
def change
   add_column :comments, :position, :text
end