草庐IT

constant-expression

全部标签

ruby-on-rails - 无方法错误 : undefined method `safe_constantize'

我有一个简单的模型:classPost它有一个名为type的INT列当我创建记录时:Post.create(:type=>1)我得到:NoMethodError:undefinedmethod`safe_constantize'for1:Fixnum我做错了什么? 最佳答案 就像这样:在Fixnum上没有名为safe_constantize的方法。type用于SingleTableInheritance.您通常会在应用程序中将已知模型的字符串表示形式作为type值。参见railsguides

ruby gem : Uninitialized constant FactoryBot

使用Rubygem并尝试在RSpec中使用FactoryBot。我在support/factory_bot.rb中有这个:RSpec.configuredo|config|config.includeFactoryBot::Syntax::Methodsconfig.before(:suite)doFactoryBot.find_definitionsendend在spec_helper.rb中:require'support/factory_bot'当我尝试运行specrake任务时,出现此错误:support/factory_bot.rb:2:in`blockin':uniniti

ruby-on-rails - 如何修复 Rake 任务中的 "uninitialized constant"

我在做的时候遇到了问题:namespace:xaarondotask:get_rolesdoroles=Xaaron::Role.allputsrolesendtask:get_role,[:name]do|t,args|role=Xaaron::Role.find(args[:name].parameterize)putsroleendend第一个任务可以正常工作。我什至可以添加binding.pry并运行Xaaron::Role并获取有关Roles的信息。但是第二个任务失败了:NameError:uninitializedconstantXaaron::Role我在我的主应用程序中

ruby-on-rails - 名称错误 : uninitialized constant Factory

我正在关注thistutorial为了与工厂女孩、rspec一起开始使用TDDonrails,我遇到了这个问题,我无法理解。这是我的“工厂”.rb(events.rb)require'faker'FactoryGirl.definedofactory:eventdoname"HIGH"genre"house,techno,idb"venue_name"WestbourneStudios"venue_address"4-6ChamberlayneRoad"venue_postcode"NW103JD"begin_time"10pm"end_time"2am"user_id2descrip

ruby - "(...) interpreted as grouped expression"是什么意思?

我在Atom中使用Rubylinter,对于某些行,它会发出以下警告:(...)interpretedasgroupedexpression获取此警告的行示例如下:elsifnot(params[:vacancy].nil?orparams[:vacancy]['company_id'].nil?orparams[:vacancy]['company_id']=="0")应该如何改进该行以使警告消失? 最佳答案 警告是(...)interpretedasgroupedexpression它的意思就是它所说的:在Ruby中,圆括号可以

ruby-on-rails - 名称错误 : uninitialized constant Faker

我正在尝试在Rails4中为我的数据库运行一个简单的bundleexecrakedb:seed。但是,在运行它时,我得到以下输出:********-C02MGBVJFD57:myapp***********$bundleexecrakedb:seedYourGemfileliststhegemfactory_girl_rails(>=0)morethanonce.Youshouldprobablykeeponlyoneofthem.Whileit'snotaproblemnow,itcouldcauseerrorsifyouchangetheversionofjustoneofthem

ruby-on-rails - Rails 3.0 & Ruby 1.9.2rc : Rake commands return 'already initialized constant' & stack level too deep errors. 任何想法

我正在尝试在Ubuntu10.04上运行Rails3beta4和Ruby1.9.2rc。它最初有效,但在完成我的第一个bundleinstall/package之后,我现在在所有Rails项目中都遇到以下错误。即使是基本的“railsnewtestproject”后跟一个rake也会显示错误消息。简而言之,我很难过。非常感谢任何有关可能导致此问题的帮助。我唯一注意到的事情——可能相关也可能不相关——是~/.bundle文件中的目录是ruby​​/1.9.1。我的机器上没有安装1.9.1-只有1.9.2rc。ruby-v带回1.9.2(in/home/john/Websites/sand

ruby - rake "already initialized constant WFKV_"警告

尝试运行rakecucumber:ok并收到此错误:/Users/dev/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rack-1.3.4/lib/rack/backports/uri/common_192。rb:53:警告:常量WFKV_已经初始化然后:命令失败,状态为(1):[/Users/dev/.rbenv/versions/1.9.2-p290/bin...]我是Rails的新手,Google没有针对此错误提供任何信息。编辑:我试过添加bundleexec,但没有任何区别。这是我用--trace得到的结果:/User

sql - 将数据从 SQL Server Express 导出到 CSV(需要引用和转义)

我花了2天时间尝试从SQLServer安装中导出一个包含用户输入数据的大型文本字段的75,000行表。此数据包含每个纯ascii字符、制表符和换行符。我需要导出CSV,其中每个字段都被引用,并且引用列中的引号被正确转义(“”)。到目前为止,这是我尝试过的:-右键单击​​ManagementStudio中的数据库并导出到Excel:由于字段太长而失败。-将数据从ManagementStudio导出到带有"文本分隔符和逗号分隔符的平面文件-完全无用,不会在字段中转义引号,使文件完全不明确。-来自命令行的BCP-也不支持引用字段。我需要使用FasterCSVruby​​库导入。它不允许引号定

ruby-on-rails - 警告 : toplevel constant referenced

我有四个模型(Document、Question、Question::Document和Answer)。在我的Answer模型中有validates:text,presence:{:unless=>Proc.new{|a|a.question.is_a?Question::Document}}这给了我警告警告:Question::Document引用的顶层常量文档如何防止出现此警告(不重命名我的类)? 最佳答案 您的文件夹/文件结构应如下所示:app/models/question/document.rbanswer.rbdocum