草庐IT

constant_time

全部标签

ruby-on-rails - 如何在 Rails 之外使用 Rails DateHelper 方法 time_ago_in_words?

因此,我下载并安装了ActiveHelpergem,但我仍然无法弄清楚如何在普通Ruby代码中使用ActionView的DateHelper方法,例如time_ago_in_words。这不包括在ActiveHelper中吗?是否可以在Rails之外使用这些方法?http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-time_ago_in_words 最佳答案 试试这个:require'action_view'require'ac

ruby-on-rails - rails : Ensure only one boolean field is set to true at a time

我有一个Logo模型,它的字段名称为:字符串,默认为bool值。我希望true值是唯一的,以便一次只能将数据库中的一项设置为true。如何在我的Controller中设置更新和新操作以将Logo的所有其余值设置为false?假设我有以下设置在我的数据库中模特标志名称:字符串|默认值:bool值|项目1|是的|项目2|假|第3项|假|如果我将Item2默认值更改为true,我希望它遍历所有Logo并将其余Logo设置为false,因此一次只有一个为true,所以它看起来像这样。名称:字符串|默认值:bool值|项目1|假|项目2|是的|第3项|假|提前感谢您的帮助。

ruby-on-rails - 为什么我使用 Rails 和 grape 得到 "Unable to autoload constant"?

我想为Android应用做一个API。搜索时,我找到了{grape}.我正在关注thistutorial,但我在启动Rails服务器时遇到问题:=>BootingWEBrick=>Rails4.0.2applicationstartingindevelopmentonhttp://0.0.0.0:80=>Run`railsserver-h`formorestartupoptions=>Ctrl-CtoshutdownserverExitingC:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.2/

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-on-rails - Time.use_zone 未按预期工作

现在是旧金山太平洋标准时间下午2:54。出于某种原因,此代码块未返回夏威夷HST中午12:54。我在这里错过了什么吗?我希望此代码返回我在夏威夷的当前时间Time.use_zone('Hawaii')doTime.nowend#=>2012-01-0314:54:54-0800 最佳答案 这应该没问题:Time.use_zone('Hawaii')dopTime.zone.nowend 关于ruby-on-rails-Time.use_zone未按预期工作,我们在StackOverflo

ruby-on-rails - 什么是 "circular argument reference"错误,有 activesupport time_zone?

我是ruby​​onrails的新手,我正在尝试创建一个教程。我在执行rakedb:migrate时遇到问题。hugo@ubuntu:~/pin_board$rakedb:migrate/home/hugo/.rvm/gems/ruby-2.2.2/gems/activesupport-4.0.5/lib/active_support/values/time_zone.rb:283:warning:circularargumentreference-now这是什么原因造成的?有人可以帮我吗? 最佳答案 您看到此警告消息是因为您的Ra

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

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