jjzjj

constant_name

全部标签

ruby-on-rails - Controller : Circular dependency detected while autoloading constant 中的 Rails 4 运行时错误

如果我遗漏了什么,请告诉我。我不明白为什么无法访问我的views/references/文件夹。new.html.erb和index.html.erb都不可用。当我转到localhost:3000/references时,我的错误是:RuntimeErrorinReferencesController#indexCirculardependencydetectedwhileautoloadingconstantReferencesController我相信这是设置,它不应该是Rails问题,因为我的其他Controller工作正常。我的路线文件中有resources:reference

ruby-on-rails - rails : Why do I get "warning: already initialized constant JSON::VERSION" when running rake cucumber?

我刚刚设置了一个LinuxMintbox,用于使用rvm进行Rails开发。我继续生成了一个Rails5应用程序,设置了mysql连接,添加了cucumber-railsgem然后尝试运行:rakecucumber出于某种原因,我遇到了:/usr/bin/ruby2.3-Sbundleexeccucumber--profiledefault/usr/lib/ruby/vendor_ruby/json/version.rb:3:warning:alreadyinitializedconstantJSON::VERSION/var/lib/gems/2.3.0/gems/json-1.8.

ruby-on-rails - 全新安装 Rails 并出现 OpenSSL 错误 : "already initialized constant OpenSSL"

我一直在尝试使用RoR。我参加了RubyInstallfest,但遇到了我认为是openssl.bundle的问题。我正在使用RVM,并且正在运行Rails5.0.1和Ruby2.4.0我尝试使用rvmimplode进行完全删除/重新启动,并重新安装了RailsAppsGuide之后的所有内容但我仍然看到相同的错误。我正在运行最新版本的macOSSierra。这是我在my_app中运行$Rake-T时得到的输出。richsmith@Richs-MacBook-Pro:~/workspace/myapp$rake-T/Users/richsmith/.rvm/rubies/ruby-2.

ruby-on-rails - PGError : ERROR: relation "table_name" does not exist

我正在尝试将一个简单的应用程序推送到heroku并运行:herokurakedb:migrate但是我得到以下错误:rakeaborted!PGError:ERROR:relation"posts"doesnotexist:SELECTa.attname,format_type(a.atttypid,a.atttypmod),d.adsrc,a.attnotnullFROMpg_attributeaLEFTJOINpg_attrdefdONa.attrelid=d.adrelidANDa.attnum=d.adnumWHEREa.attrelid='"posts"'::regclass

ruby - regexp\k<name+0> 中的 "+0"是什么意思?

我是Ruby中正则表达式的新手,我似乎找不到任何关于\k内容的可靠文档。方法。这是+0我没有得到的部分。这是一个例子——这个正则表达式匹配回文:\A(?(?:(?\w)\g\k|\w))\z当我删除+0在\k它不再正确匹配。我的测试:>>/\A(?(?:(?\w)\g\k|\w))\z/.match"aabbcdcbbaa"#=>#>>/\A(?(?:(?\w)\g\k|\w))\z/.match"aabbcdcbbaa"#=>nil我所做的就是删除+0.我还没有找到任何文档或示例,任何人都可以指出正确的方向吗? 最佳答案 \k与(

Ruby Koans #75 test_constants_become_symbols,正确答案?

我的问题基于这个问题:RubyKoan:Constantsbecomesymbols.我有以下代码:in_ruby_version("mri")doRubyConstant="Whatisthesoundofonehandclapping?"deftest_constants_become_symbolsall_symbols=Symbol.all_symbolsassert_equal__,all_symbols.include?(__)endend正确答案应该是下面的吗?assert_equaltrue,all_symbols.include?("RubyConstant".to_

ruby-on-rails - map(& :name) do in this Ruby code? 是什么意思

为了更好地理解Ruby,我在网上冲浪时遇到了这段代码:require'rubygems'require'activeresource'ActiveResource::Base.logger=Logger.new("#{File.dirname(__FILE__)}/events.log")classEvent"Shortesteventevar!",:starts_at=>1.second.ago,:capacity=>25,:price=>10.00)e.destroy我特别感兴趣的是events.map(&:name)是如何工作的?我看到events是一个数组,因此它调用了它的ma

ruby 公案 : Constants become symbols

在about_symbols.rbRubyKoan(https://github.com/edgecase/ruby_koans)中,我有以下代码:RubyConstant="Whatisthesoundofonehandclapping?"deftest_constants_become_symbolsall_symbols=Symbol.all_symbolsassert_equaltrue,all_symbols.include?(:"nonexistent")assert_equaltrue,all_symbols.include?(:"Whatisthesoundofoneh

ruby-on-rails - rails : dynamically define class method based on parent class name within module/concern

我想根据包含此Mixin的类名在Mixin中动态生成一个类方法。这是我当前的代码:moduleMyModuleextendActiveSupport::Concern#defsome_methods#...#endmoduleClassMethods#HereiswhereI'mstuck...define_method"#{self.name.downcase}_status"do#dosomething...endendendclassMyClass但这给了我以下方法名称:MyClass.mymodule::classmethods_status在方法定义中获取基类名称是可行的(s

ruby-on-rails - 知道@vendor.name 后如何使 Ruby on Rails 中的 URL 对 SEO 友好?

我的应用程序在RoR中我有一个名为showsummary的操作/View,其中ID已传递到URL,并且Controller使用它来实例化@vendor,其中@vendor.name是公司的名称。我希望URL是showsummary/1/而不是在URL中包含/vendor-name。我该怎么做? 最佳答案 所有这些解决方案都使用find_by_name,这肯定需要在该列上有一个索引并且要求它们是唯一的。我们使用的一个更好的解决方案是在供应商名称前加上其ID,但牺牲了一点美观。这意味着您不必在名称列上有索引和/或要求唯一性。供应商.rb