草庐IT

namespace-scoped

全部标签

ruby-on-rails - 具有管理 namespace 的 Rails 3 中的 I18n

我正在根据Rails指南的建议开发Rails应用程序,以创建包含翻译的文件夹树和文件。我的文件夹树与此类似:|-defaults|---es.rb|---en.rb|-models|---book|-----es.rb|-----en.rb|-views|---defaults|-----es.rb|-----en.rb|---books|-----es.rb|-----en.rb|---users|-----es.rb|-----en.rb|---navigation|-----es.rb|-----en.rbconfig/locales/views/books/en.yml中的内容

ruby - 续集中的 default_scope

在ActiveRecord中有一个default_scope类方法来指定默认范围。例如classUserfalse)endUser.all#=>SELECT*FROMusersWHEREdeleted=0;我如何在Sequel::Model中执行此操作?编辑:经过一番谷歌搜索,我终于找到了一些有用的信息。classUser生成的查询如下所示:User.all#=>SELECT*FROM`users`WHERE(`deleted`ISFALSE)顺便说一下:unscoped等同于unfiltered:User.unfiltered.all#=>SELECT*FROM`users`但是,有

ruby-on-rails - rails : has_many through not returning correctly with namespaced models

我有3个模型。Rom::Favorite,Rom::Card,User。我在创建Userhas_manyrom_cardsthroughrom_favorites时遇到问题这是我模型的相关部分Rom::CardclassRom::Card用户classUserRom::收藏classRom::Favorite{:scope=>:user_id}self.table_name="rom_favorites"end除了之外,关联的所有实用方法都有效a=User.find(1)a.rom_cards调用a.rom_cards返回一个空数组,它似乎运行了这个SQL查询SELECT"rom_fa

ruby /萨翁 : Having trouble with namespace for a soap request

我在更改正在构建的SOAPxml的命名空间时遇到问题。我不确定如何将“xmlns:env=”更改为“xmlns:soapenv=”,将“xmlns:tns=”更改为“xmlns:web=”我要构建的内容:100degreeCelsiusdegreeFahrenheit我目前得到的100degreeCelsiusdegreeFahrenheit我的代码:client=Savon.client(wsdl:"http://www.webservicex.net/ConvertTemperature.asmx?WSDL")message={temperature:'100',FromUnit:

ruby-on-rails - Rails 3.2 ActiveAdmin 'Collection is not a paginated scope.' 错误

我正在使用Rails3.2和ActiveAdmin0.4.4开发应用程序。我有一个名为Teaser的模型(/app/models/teaser.rb):classTeasertruemount_uploader:img,TeaserUploaderend然后我向其中添加了ActiveAdmin(/app/admin/teaser.rb):#encoding:UTF-8ActiveAdmin.registerTeaserdoformdo|f|f.inputs"Teaser"dof.input:name,:label=>'Текст'f.input:url,:label=>'Ссылка'

ruby - RSpec 2之前(:suite) variable scope

基本上我想创建一个数组,然后在我的规范中附加到它,然后再最终处理并将它显示给用户。我可以想出一些解决方法,但理想情况下我想执行以下操作。RSpec.configuredo|config|config.before(:suite){@array_of_stuff||=[]}config.after(:suite){process_and_print(@array_of_stuff)}enddefprocess_and_print(array)#dostuffend不幸但并不令人惊讶的是@array_of_stuff不在范围内并且不能从我的规范中追加,这与在before(:all)bloc

ruby-on-rails - 为什么我得到 "including Capybara::DSL in the global scope is not recommended!"

每次我运行规范,即使规范通过,例如$rspecspec/integration/view_homepage_spec.rbincludingCapybara::DSLintheglobalscopeisnotrecommended!.Finishedin0.6174seconds1example,0failuresRandomizedwithseed14130$我的Gemfile有:group:test,:developmentdogem'rspec-rails'gem'capybara'end我的spec_helper有:ENV["RAILS_ENV"]||='test'requir

Ruby 范围,常量优先级 : lexical scope or inheritance tree

我将向您展示来自rubykoans的代码片段教程。考虑下一个代码:classMyAnimalsLEGS=2classBird实际上问题在评论中(我用星号突出显示了它(尽管它打算以粗体显示))。有人可以解释一下吗?提前致谢! 最佳答案 这里有答案:Ruby:explicitscopingonaclassdefinition.但也许它不是很清楚。如果您阅读链接的文章,它将帮助您找到答案。基本上,Bird是在MyAnimals的范围内声明的,在解析常量时具有更高的优先级。Oyster位于MyAnimals命名空间中,但未在该范围内声明。将

ruby-on-rails - rails 路线 : define root to namespace

我有2个Controller:app//controllersposts_controllers.rb/mobileposts_controllers.rb我的routes.rb看起来像这样:root:to=>"posts#index"resources:postsnamespace:mobiledoroot:to=>"posts#index"resources:postsend但是当我访问/mobile时,它无论如何都会渲染第一个Controller的索引页面,也试过这个:namespace:mobiledoroot:to=>"mobile/posts#index"resources

ruby-on-rails - 如何解决 Rails 模型 namespace 冲突

到目前为止的故事:我有一个Rails应用程序,其模型名为“Term”。在尝试安装Cucumber之前一切都很好。运行时rakecucumber我明白了Termisnotaclass(TypeError)发生这种情况是因为Cucumber包含另一个gem,'term-ansicolor'(在控制台中执行漂亮的彩色文本输出),并且term-ansicolor定义了一个名为“Term”的模块。Cucumber在包含Rails模型之前包含term-ansicolor,因此在加载“Term”模型时“Term”已经被定义为一个模块。顶级模块和类在Ruby中不能有相同的名称,因此会发生冲突。不想重命