草庐IT

constant_fields

全部标签

ruby-on-rails - 路由错误 : Uninitialized constant in Rails 3

我有一个包含类似这样的辅助类的文件:应用程序/类/myfile.rbModulemymoduleclassmyclass#blahblahendend我想在Controller中使用这个类,所以我写了这样的东西:require'myfile'classMyControllerController的路由定义如下:match'mycontroller',:to=>'mycontroller#index'现在是我面临的奇怪行为。它在服务器启动后的第一次运行中工作得很好。但是,当我刷新页面或再次点击URL时,出现以下错误。RoutingErroruninitializedconstantMyC

ruby - 运行时错误 : Circular dependency detected while autoloading constant

我通过引入请求和响应模型来重构我的Controller,以执行此presentation之后Controller周围的一些逻辑。.我分别用模块Responses和Requests包装了所有的响应和请求模型。应用程序运行完美,但当我运行测试时,出现以下错误。Failure/Error:UnabletofindmatchinglinefrombacktraceRuntimeError:CirculardependencydetectedwhileautoloadingconstantResponses::FolderContentResponse我的目录结构如下:-应用/-模型/-回应/注

ruby-on-rails - rails : How to insert a text_field without a form just to test the layout?

我现在正在为我的应用程序做布局,我想插入一个不执行任何操作的text.field,只是为了看看它的外观。我该怎么做? 最佳答案 有几种方法可以满足您的需求。1)只写静态HTML2)使用text_field_tag3)使用form_for为虚拟对象构建虚拟表单 关于ruby-on-rails-rails:Howtoinsertatext_fieldwithoutaformjusttotestthelayout?,我们在StackOverflow上找到一个类似的问题:

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 - text_field 在 Ruby on Rails 中被禁用

当用户不是管理员并且它工作正常时,我有以下代码来禁用text_field:但是当用户是管理员时,text_field就会消失。有谁知道为什么会这样以及我必须做什么? 最佳答案 假设is_admin?返回true或false,您可以简单地做目前,if条件,即ifnotis_admin?应用于整个文本字段,这导致is_admin?时文本字段消失。code>返回true,当条件返回false时显示文本字段。 关于ruby-on-rails-text_field在RubyonRails中被禁用,

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 - rails : Using form fields that are unassociated with a model in validations

在RubyonRails应用程序中,我尝试使用来自与验证模型无关的字段的信息。这里以模型的一部分为例(整个模型有点大):classScorecard那么如何从模型中访问params呢? 最佳答案 不要让参数偷偷靠近模型。在这种情况下没有Controller的意义。相反,从Railscasts查看这一集它讨论了不进入数据库但仍可用于验证的虚拟属性。虚拟属性不需要相应的模型属性。定义类的局部属性,例如保存状态的@no_fairways。classScoreCard现在在你的表单中,你可以写:

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 - Rails 中带有 text_field 的逗号分隔数组

我有一些用户可以有很多帖子,并且每个帖子都可以有很多标签。我已经使用帖子和标签之间的has_and_belongs_to_many关系实现了这一点。创建新帖子时,用户可以使用逗号分隔的值列表对其进行标记(很像在SO上发布新问题时)。如果任何标签尚不存在,则应自动创建。这是帖子的_fields.html.erb部分内容:f.object%>现在使用f.text_field:tags会生成带有[]文本的输入元素。我还没有在posts_controller.rb中使用标签,因为我不确定我应该如何从参数中获取和拆分字符串值:defcreate@post=current_user.posts.b