Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.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 5属于默认行为 开始 需要“bundler/inline” rescue LoadError=>e $stderr.puts“需要Bundler版本1.10或更高版本。请更新您的Bundler” 提高e 结束 gemfile(true)do 来源“https://rubygems.org" gem“rails”,github:“rails/rails” gem“sqlite3” 结束 需要“活动记录” 需要“微型测试/自动运行” 需要“记录器” #此连接适用于独立于数据库的错误报告。 ActiveRecord::Base.建立\u连接(适配器:“sqlite3”,数据库:::内存:) ActiveRecord::Base.logger=logger.new(标准输出) ActiveRecord::Schema.define do 创建|表:posts,force:true do | t| 结束 创建表格:注释,强制:真do | t| t、 整数:post_id 结束 结束 类Post_Ruby On Rails_Activerecord_Rails Activerecord - Fatal编程技术网

Ruby on rails Rails 5属于默认行为 开始 需要“bundler/inline” rescue LoadError=>e $stderr.puts“需要Bundler版本1.10或更高版本。请更新您的Bundler” 提高e 结束 gemfile(true)do 来源“https://rubygems.org" gem“rails”,github:“rails/rails” gem“sqlite3” 结束 需要“活动记录” 需要“微型测试/自动运行” 需要“记录器” #此连接适用于独立于数据库的错误报告。 ActiveRecord::Base.建立\u连接(适配器:“sqlite3”,数据库:::内存:) ActiveRecord::Base.logger=logger.new(标准输出) ActiveRecord::Schema.define do 创建|表:posts,force:true do | t| 结束 创建表格:注释,强制:真do | t| t、 整数:post_id 结束 结束 类Post

Ruby on rails Rails 5属于默认行为 开始 需要“bundler/inline” rescue LoadError=>e $stderr.puts“需要Bundler版本1.10或更高版本。请更新您的Bundler” 提高e 结束 gemfile(true)do 来源“https://rubygems.org" gem“rails”,github:“rails/rails” gem“sqlite3” 结束 需要“活动记录” 需要“微型测试/自动运行” 需要“记录器” #此连接适用于独立于数据库的错误报告。 ActiveRecord::Base.建立\u连接(适配器:“sqlite3”,数据库:::内存:) ActiveRecord::Base.logger=logger.new(标准输出) ActiveRecord::Schema.define do 创建|表:posts,force:true do | t| 结束 创建表格:注释,强制:真do | t| t、 整数:post_id 结束 结束 类Post,ruby-on-rails,activerecord,rails-activerecord,Ruby On Rails,Activerecord,Rails Activerecord,使用当前的rails master,此测试失败。 我认为它应该成功,因为属于Rails 5默认要求的 这是预期的行为吗?你说得对,属于在Rails 5中默认是必需的。在您的示例中,您没有运行Rails 5应用程序,您只是在使用ActiveRecord Rails 5中默认情况下需要属于,因为当您生成一个新的Rails 5应用程序时,您会得到一个文件config/initializers/new\u framework\u defaults.rb,该文件具有以下行: begin req

使用当前的rails master,此测试失败。 我认为它应该成功,因为
属于Rails 5默认要求的


这是预期的行为吗?

你说得对,
属于
在Rails 5中默认是必需的。在您的示例中,您没有运行Rails 5应用程序,您只是在使用
ActiveRecord

Rails 5中默认情况下需要
属于
,因为当您生成一个新的Rails 5应用程序时,您会得到一个文件
config/initializers/new\u framework\u defaults.rb
,该文件具有以下行:

begin
  require "bundler/inline"
rescue LoadError => e
  $stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
  raise e
end

gemfile(true) do
  source "https://rubygems.org"
  gem "rails", github: "rails/rails"
  gem "sqlite3"
end

require "active_record"
require "minitest/autorun"
require "logger"

# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)

ActiveRecord::Schema.define do
  create_table :posts, force: true do |t|
  end

  create_table :comments, force: true do |t|
    t.integer :post_id
  end
end

class Post < ActiveRecord::Base
end

class Comment < ActiveRecord::Base
  belongs_to :post
end

class BugTest < ActiveSupport::TestCase
  def test_association_stuff
    post = Post.create!

    comment = Comment.create
    assert_not_empty comment.errors.full_messages
  end
end
为了在您的示例中获得类似的结果,您还必须为
ActiveRecord
设置此配置选项(默认情况下未设置此选项,这意味着它是
nil
,也称为falsy值):

#此连接适用于独立于数据库的错误报告。
ActiveRecord::Base.建立\u连接(适配器:“sqlite3”,数据库:::内存:)
ActiveRecord::Base.logger=logger.new(标准输出)

ActiveRecord::Base.allows_to_required_默认值=true#你说得对,
allows_to
在Rails 5中默认值是必需的。在您的示例中,您没有运行Rails 5应用程序,您只是在使用
ActiveRecord

Rails 5中默认情况下需要
属于
,因为当您生成一个新的Rails 5应用程序时,您会得到一个文件
config/initializers/new\u framework\u defaults.rb
,该文件具有以下行:

begin
  require "bundler/inline"
rescue LoadError => e
  $stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
  raise e
end

gemfile(true) do
  source "https://rubygems.org"
  gem "rails", github: "rails/rails"
  gem "sqlite3"
end

require "active_record"
require "minitest/autorun"
require "logger"

# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)

ActiveRecord::Schema.define do
  create_table :posts, force: true do |t|
  end

  create_table :comments, force: true do |t|
    t.integer :post_id
  end
end

class Post < ActiveRecord::Base
end

class Comment < ActiveRecord::Base
  belongs_to :post
end

class BugTest < ActiveSupport::TestCase
  def test_association_stuff
    post = Post.create!

    comment = Comment.create
    assert_not_empty comment.errors.full_messages
  end
end
为了在您的示例中获得类似的结果,您还必须为
ActiveRecord
设置此配置选项(默认情况下未设置此选项,这意味着它是
nil
,也称为falsy值):

#此连接适用于独立于数据库的错误报告。
ActiveRecord::Base.建立\u连接(适配器:“sqlite3”,数据库:::内存:)
ActiveRecord::Base.logger=logger.new(标准输出)

ActiveRecord::Base.allows_to_required_默认值为true 35;我对测试应该成功的期望是错误的,因为我使用了#create!我对测试应该成功的期望是错误的,因为我使用了#create!而不是创造。
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.belongs_to_required_by_default = true # <-- This line :)