草庐IT

custom-attribute

全部标签

ruby-on-rails - Rails 3 如何允许在没有_attributes 指定的情况下传递嵌套属性

当使用accepts_nested_attributes_for时,我不想传递“child_attributes”,而是传递“child”。我很确定,如果我在我的Controller中放入大量逻辑来创建记录和子项,我就可以完成此操作。但是,为了使我的Controller保持干净和逻辑应有的位置,即本例中的模型,我想知道如何在执行POST或PUT时切换rails3以使用此语法。{"name":"test","child_attributes":[{"id":1,"name":"test_child_update"},{"name":"test_child_create"}}相当{"nam

ruby : how to prevent modification of an array instance variable through an attribute reader

抱歉这个菜鸟问题...假设我们有:classTestMeattr_reader:arraydefinitialize@array=(1..10).to_aend结束然后可以这样做:>>a=TestMe.new=>#>>a.array.map!&:to_s=>["1","2","3","4","5","6","7","8","9","10"]>>a.array=>["1","2","3","4","5","6","7","8","9","10"]这显然不利于封装,不是吗?有什么方法可以快速保护数组变量不被更改吗?...或者每当我的实例变量具有“破坏性”方法时,我是否需要实现一个深拷贝读取

ruby-on-rails - Ruby on Rails : How to validate nested attributes on certain condition?

我有这些模型:classOrganisation:addressable,:dependent=>:destroyaccepts_nested_attributes_for:address,:allow_destroy=>trueendclassPerson:addressable,:dependent=>:destroyaccepts_nested_attributes_for:address,:allow_destroy=>true#Thesetwomethodsseemtohavenoeffectatall!validates_presence_of:organisation,:

ruby - Firebase token 错误, "The custom token corresponds to a different audience."

我正在尝试在服务器上使用Ruby为Firebase生成JWTtoken。在3.0之前我们使用tokengenerator但升级后它停止工作。我用下面的代码得到的token给出了一个错误:Thecustomtokencorrespondstoadifferentaudience.我到处都找不到它的意思。private_key=OpenSSL::PKey::RSA.new谢谢 最佳答案 我也遇到了这个错误,我得到它是因为我使用了一个与firebase项目无关的服务帐户。在firebase项目下使用新key创建新服务帐户后,它开始工作。要

ruby-on-rails - rails : link_to calls custom method in controller

我希望使用link_to来调用我的Controller中的方法。但是,由于某些奇怪的原因,路由会寻找show方法。在我看来:..beverage.id)%>..在我的config/routes.rb中match'beverages/archive'=>'beverages#archive'在我的beverages_controller.rb中defarchivebeverage=Beverage.find(params[:id])respond_todo|format|#format.html#show.html.erbformat.json{renderjson:beverage}e

ruby - 卡皮斯特拉诺 3 : use server custom variable in task

我有多阶段多服务器设置,在我的任务中我需要使用服务器名称例如在stagin.rb我有:set:stage,:staging#Defineserversserver'xxx.xx.xx.xxx',user:'deploy',roles:%w{app},name:'app1'server'xxx.xx.xx.yyy',user:'deploy',roles:%w{app},name:'app2'我想在我的任务中使用那个“名称”变量:task:configuredoonroles(:app),in::paralleldo#howdoIgetservernamehere?endend

ruby-on-rails - Rails 4 强参数 : can I 'exclude' /blacklist attributes instead of permit/whitelist?

我正在将Rails3应用程序迁移到Rails4,并且正在将attr_accessible属性转换为Controller中的强参数。APIDocumentation显示如何“允许”属性:defperson_paramsparams.require(:person).permit(:name,:age)end然而,我的绝大多数属性都是批量分配安全的。我只需要将:account_id和:is_admin等几个属性列入黑名单。是否可以将属性列入黑名单而不是将几乎所有属性列入白名单?例如:defuser_paramsparams.require(:user).exclude(:account_i

ruby-on-rails - 错误 : When assigning attributes, 您必须将散列作为参数传递

嗨,我刚开始使用ruby​​,我正在编写Controller和Controller规范,但我遇到了一些问题。文档.rbclassDocument文档Controller.rbclassAPI::DocumentsControllerdocuments_controller_spec.rbdescribe"POST'index'"dobefore{@attr=FactoryGirl.attributes_for(:document)}describe"failure"dodescribe"withmissingparameters"dobefore{@attr.each{|key,val

ruby - custom_require.rb :36:in `require' : no such file to load -- myapp(LoadError)

我收到上述错误,我所做的只是安装rvm并从您使用mac获得的默认ruby​​更新到ruby​​1.9.2。我所有的gem都出现在gem列表中,但我需要在某处指定路径吗?干杯,格伦诺。 最佳答案 检查你是否安装了gemsgemlist如果没有,照常安装geminstallwhatever或者如果你想要特定版本geminstallwhatever-v1.2.3或者如果你的项目中有bundler(即Rails),它只是bundleinstall如果您拥有所有的gem,那么这可能是一个本地文件,并且您可能来自Ruby版本$LOAD_PATH

ruby-on-rails - rails 3 : User Created custom forms?

我正在努力思考如何允许用户创建具有所有字段类型的自定义表单。如果有一颗gem就好了,但我似乎无法在任何地方找到。所以我有一个像这样的数据库设置:t.integer:form_idt.string:namet.string:hintt.integer:positiont.string:field_typet.boolean:requiredt.integer:sizet.boolean:multiplet.text:valuest.timestamps这就是我所在的位置。我想不出如何遍历field_type并返回值,以及将它们与实际填写的表单相关联。谢谢 最佳