jjzjj

entity-attribute-value

全部标签

ruby-on-rails - self.send(method, =, value) 不起作用

我正在尝试创建一个Ruby类,其中initialize方法接受选项的散列。然后,我将这些选项作为类的attr_accessor。现在,我可以做类似的事情classUserattr_accessor:name,:email,:phonedefinitialize(options)self.name=options[:name]self.email=options[:email]self.phone=options[:phone]endendUser.new(:name=>'SomeName',:email=>'some-name@some-company.com',:phone=>435

ruby 心印 : Where are the quotes in this return value?

我正在研究以下RubyKoan:classDog7attr_reader:namedefinitialize(initial_name)@name=initial_nameenddefget_selfselfenddefto_s__enddefinspect""endenddeftest_inside_a_method_self_refers_to_the_containing_objectfido=Dog7.new("Fido")fidos_self=fido.get_selfassert_equal"",fidos_selfenddeftest_to_s_provides_a_st

ruby-on-rails - 警告 : Can't mass-assign protected attributes

当发帖到/:username/about时,我收到“警告:无法批量分配protected属性:about”。classAbout["lower(username)=?",params[:username].downcase])iftrue@about=@user.aboutif@about.update_attributes(params[:about])flash[:notice]="Successfullyupdatedpost."respond_with(@about,:location=>about_path(@about.user.username))elseredirect

ruby-on-rails - "Expected string default value for ` --jbuilder `; got true (boolean)"新建rails项目出错

我正在开始一个新项目,现在已经做了很多次了。但是,这是我第一次遇到这个问题!我正常创建应用railsnewmyapp-dpostgresql我使用railsdb:create创建了数据库并运行了站点railss。一切正常,我看到了Rails欢迎/等待页面。现在我开始创建我的模型,例如railsgmodeluser。我明白了!Expectedstringdefaultvaluefor`--jbuilder`;gottrue(boolean)invokeactive_recordThename'User'iseitheralreadyusedinyourapplicationorreser

ruby-on-rails - 切换到 Rails 4.1 时出现错误 - `method_missing':ActiveRecord::Base:Class (NoMethodError) 的未定义方法 `whitelist_attributes='

从Rails4.0切换到Rails4.1时出现此错误:activerecord-4.1.8/lib/active_record/dynamic_matchers.rb:26:in`method_missing':undefinedmethod`whitelist_attributes='forActiveRecord::Base:Class(NoMethodError)我没有在我的应用程序的任何地方使用attr_accessible或attr_protected所以我想知道为什么我有问题。当迁移到Rails4.0时,我已经安装了我的application.rb:配置/应用程序.rb:c

ruby-on-rails - rails : Copying attributes from an object to another using the "attributes" method

让模型Quote具有属性[price,description]让模型Invoice有属性[price,description,priority]让invoice模型Invoice中的对象具有属性{price:10,description:'lamp',priority:10}invoice={price:10,description:'lamp',priority:10}假设我想将invoice属性复制到新的quote。quote=Quote.new(invoice.attributes)这会引发一个错误,即priority在模型Quote中不存在。如何将invoice属性复制到新的q

ruby-on-rails - 如何修复 Rails 中 pg_attribute 表的缓慢隐式查询

在我们的生产环境中,我们注意到Rails应用程序频繁出现峰值(大约每1小时一次)。深入挖掘,这是由于以下查询在单个HTTP请求中累计运行时间超过1.5秒(称为100倍)。SELECTa.attname,format_type(a.atttypid,a.atttypmod),pg_get_expr(d.adbin,d.adrelid),a.attnotnull,a.atttypid,a.atttypmodFROMpg_attributeaLEFTJOINpg_attrdefdONa.attrelid=d.adrelidANDa.attnum=d.adnumWHEREa.attrelid=

ruby-on-rails - 在模型中使用 self.attribute 和 attribute 有什么区别?

在RubyonRails中,在模型中使用self.attribute和attribute有什么区别?在此示例中,假设my_attr是存储在数据库中的用户属性。classUser 最佳答案 您的示例的不同之处在于第一个有效,第二个无效。您的第二个版本没有做任何事情(至少没有任何意义)。编写my_attr=123不等同于self.my_attr=123。相反,它会创建一个名为my_attr的局部变量并将其设置为123,然后立即到达方法的末尾并丢弃my_attr。整个方法本质上是一个no-op,它不会以任何方式影响模型的my_attr值。

ruby-on-rails - 尝试更新数据库值时,rails update_attributes 返回 false

希望这里有人能给我指出正确的方向。我有一个ControllerUpdatedef运行“update_attributes”。目前它返回false,没有错误消息。我是Ruby的新手,但不是编码的新手,这让我困惑了好几天!我正在尝试使用下面指定的值更新用户模型和数据库。defupdate#getcurrentlyloggedinuser@user=current_user#updateuserparamsbasedoneditform...if@user.update_attributes(params[:user])redirect_toprofile_path,:notice=>"Su

ruby-on-rails - I18n : How to check if a translation key/value pairs is missing?

我正在使用RubyonRails3.1.0和I18ngem.我(正在实现一个插件)我想在运行时检查I18n是否缺少翻译键/值对,如果是,则使用自定义字符串。也就是说,我有:validates:link_url,:format=>{:with=>REGEX,:message=>I18n.t('custom_invalid_format',:scope=>'activerecord.errors.messages')}如果.yml文件中没有如下代码activerecord:errors:messages:custom_invalid_format:Thisisthetesterrormes