草庐IT

namespaces

全部标签

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-on-rails - 如何将 "import"嵌套类放入 Ruby 中的当前类?

在Ruby中,我可以将模块/类嵌套到其他模块/类中。我想要的是在文件或类中添加一些声明,以便能够通过短名称引用嵌套类,例如使用Inner获取Outer::Inner,就像在Java、C#等中一样。语法可能是这样的:moduleOuterclassInner;endclassAnotherInner;endendclassCimportOuter:[:Inner,:AnotherInner]deffInnerendend简单的实现可能是这样的:classClassdefimport(constants)@imported_constants=(@imported_constants||{

ruby-on-rails - 自动加载路径和嵌套服务类在 Ruby 中崩溃

我在Rails5项目的app/services文件夹下有多个加载/需要类的问题,我开始放弃这个问题。首先要明确的是,services/是我在整个项目中使用的简单PORO类,用于从Controller、模型等中抽象出大部分业务逻辑。树看起来像这样app/services/my_service/base.rbfunny_name.rbmy_service.rbmodels/funny_name.rb失败#1首先,当我尝试使用MyService.const_get('FunnyName')时,它从我的模型目录中获取了FunnyName。当我直接执行MyService::FunnyName时,

ruby - 是否有可能缩小 ruby 常量查找

我有一个模块,其中包含名为String的类(以及其他类。)我需要按名称查找该类,如果没有这样的类,则优雅地回退。moduleMod1moduleStringendendMod1.const_get'String'#⇒Mod1::StringKernel.const_get'::Mod1::String'#⇒Mod1::String到目前为止,还不错。当我尝试查找不存在的类时,我预计会收到NameError,这很好。问题是如果在全局命名空间中存在一个具有给定名称的类,它将被返回:Mod1.const_get'Fixnum'#⇒Fixnum我明白其中的原因,但我的问题是:是否有现成的方法仅

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 路线 : 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 - 将 Ruby gem 加载到用户定义的命名空间中

如果一个gem定义了与我编写的某些代码冲突的顶级类,是否可以要求gem的所有类都分组在我可以定义的模块中?例如,如果unsafe_gem定义了一个类:classWord#...somecodeend我需要这样的东西:classWord#Mywordclass.endmoduleSafeContainer#Thisobviouslydoesn'twork#(i.e.thegemstilldefines::Word).require'unsafe_gem'end这样我就可以区分:Word.new#=>TheclassIdefined.SafeContainer::Word.new#=>Th

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中不能有相同的名称,因此会发生冲突。不想重命

ruby-on-rails - ruby 命名空间

我是ruby​​的新手,来自php背景,但有些东西不适合我。所以,假设我有一个RubyonRails应用程序,并且我正在像这样对我的API进行版本控制:app|_controllers|_api||_v1|||_application_controller.rb|||_user_controller.rb||_application_controller.rb|_application_controller.rb与类结构同#VersionedAPIV1appcontrollermoduleApimoduleV1classApplicationControllerendendend#Ve