search

Home  >  Q&A  >  body text

ruby - (ActiveRecord::ConnectionNotEstablished)

require 'active_record'

class Movie < ActiveRecord::Base
end


movie = Movie.new(1)
movie.title = "Doctor Strangelove"
movie.director = "Stanley Kubrick"

以上代码运行报错:

in `retrieve_connection': No connection pool for Movie (ActiveRecord::ConnectionNotEstablished)

不知为什么。

PHP中文网PHP中文网2775 days ago666

reply all(1)I'll reply

  • 迷茫

    迷茫2017-04-24 09:16:00

    Look at your code. You should be reading ruby ​​metaprogramming second edition

    But you didn’t read it carefully. The clear explanation of this code in the book is as follows: This code creates a record in the movies table, title
    and director. You should not have created a database or have no connection to the database this time. Recording failed

    Have a good look at activerecord

    reply
    0
  • Cancelreply