草庐IT

valid_domain

全部标签

ruby-on-rails - validates_inclusion_of 在 Rails 4.1 中不再正常工作?

以下代码确保选择的time_zone在ActiveSupport::TimeZone.us_zones中的时区内:validates_inclusion_of:time_zone,in:ActiveSupport::TimeZone.zones_map(&:name)在Rails4.0中表现出色。刚刚升级到Rails4.1,我的索引页面上出现了这个错误(所以只是简单地查看模型):Anobjectwiththemethod#include?oraproc,lambdaorsymbolisrequired,andmustbesuppliedasthe:in(or:within)option

ruby-on-rails - rails : why is calling to_a on a string not valid in a rake task?

我正在尝试解密一组用于数据库迁移的密码。我有一些旧的Rails代码(实际上是一个Runner脚本)可以很好地解密它们。但是将相同的代码放入Rake任务会导致任务失败,并显示...未定义的方法`to_a'for"secretkey":String...为什么在字符串上调用to_a在Rake任务中无效,但在Runner脚本中却完全有效?require'openssl'KEY='secretkey'namespace:importdotask:users=>:environmentdodefdecrypt_password(pw)cipher=OpenSSL::Cipher::Cipher.

ruby-on-rails - 什么是 :domain symbol referring to when configuring action mailer?

Appname::Application.configuredoconfig.action_mailer.delivery_method=:smtp#typicalsmtp_settingsforgmailaccountconfig.action_mailer.smtp_settings={:address=>"smtp.gmail.com",:port=>587,:domain=>"domain.of.sender.net",:authentication=>"plain":user_name=>"spencecooley":password=>"secret":enable_sta

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

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

ruby - "Error validating client secret."404 与 Facebook Oauth 和 ruby

我正在尝试使用warden为应用程序实现facebook身份验证,在用户允许facebook身份验证并使用token重定向到我的应用程序回调后,我在使用api时得到400。我的典狱长策略是这样的:classFacebook'https://graph.facebook.com'enddefparams@params||=Rack::Utils.parse_query(request.query_string)enddefauthorize_urlclient.web_server.authorize_url:redirect_uri=>request.url,:scope=>'emai

ruby-on-rails - ruby rails : question about validates_presence_of

我在基于ActiveRecord的模型中有一个如下所示的关系:belongs_to:foo我的模型应该始终在其中定义foo才能有效。我的问题是,当使用validates_presenceof时,使用哪个是合适的:validates_presence_of:foo或validates_presence_of:foo_id当然,这里假设foo_id是适当的外键,如果您不更改关联键,则默认情况下它是。 最佳答案 第一个:validates_presence_of:foo(尽管我认为第二个也可以)。通常,Ruby验证助手处理模型名称而不是显

ruby-on-rails - Rails 嵌套 with_option :if used in validation

validate:updatable?#Firstvalidationthereiswith_options:if=>Proc.new{|object|object.errors.empty?}do|updatable|updatable.with_options:if=>"self.current_step==basic"do|step|validates....bla-blabla因此,在进行任何验证之前,updatable子例程被调用,它用适当的错误填充errors[:base]数组,这意味着该对象不可更新.如果在此子例程中发现任何错误,我希望它跳过其余的验证,但上述示例不工作-

ruby-on-rails - rails 3 : how to generate custom error message from failed validation

我正在使用validates:feed_id,presence:true,uniqueness:true我应该如何生成自定义错误消息以指定用户已经订阅了此提要(feed_id)字段重复我知道我可以只做validate_uniqueness_of但它会不必要地使代码困惑。如果唯一性验证失败,我该如何传递特定的错误消息?? 最佳答案 使用键message和期望的消息作为值而不是true放置一个散列:validates:feed_id,presence:true,uniqueness:{message:"alreadysubscribed

ruby-on-rails - postgresql 数据库错误 : Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

当我运行rakedb:migrate或运行railss命令时,我得到同样的错误:Error:couldnotconnecttoserver:NosuchfileordirectoryIstheserverrunninglocallyandacceptingconnectionsonUnixdomainsocket"/var/run/postgresql/.s.PGSQL.5432"?当我尝试railss时,浏览器出现错误。这是我的database.ymldefault:&defaultadapter:postgresqlencoding:unicodepool:5development