草庐IT

get-unread-emails-from-gmail-usin

全部标签

ruby - 为什么在:save callback hook not getting called from FactoryGirl. create()之前?

这个简单的示例使用DataMapper的before:save回调(又名Hook)来增加callback_count。callback_count初始化为0,回调应该设置为1。当通过以下方式创建TestObject时调用此回调:TestObject.create()但是当FactoryGirl通过以下方式创建时会跳过回调:FactoryGirl.create(:test_object)知道为什么吗?[注意:我正在运行ruby​​1.9.3,factory_girl4.2.0,data_mapper1.2.0]详细信息如下...DataMapper模型#file:models/test_

ruby-on-rails - 葡萄 : Rescue from invalid JSON

首先:我正在使用grape构建我的API(Rails4)。当有人发送无效的JSON正文时(例如忘记最后一个}),会引发以下错误:ActionDispatch::ParamsParser::ParseError(795:unexpectedtokenat'{"foobar":1234')我尝试使用grapesrescue_from:all选项,但这不起作用。在堆栈跟踪中,我没有看到涉及的葡萄gem。这个错误似乎是从actionpack中抛出的:.gems/gems/actionpack-4.1.4/lib/action_dispatch/middleware/params_parser.

ruby - 使用 gmail gem 跟踪一些电子邮件

我正在使用gmailgem发送电子邮件,我需要跟踪这些电子邮件。我该怎么做?我正在尝试搜索带有message_id的电子邮件,但它会从我的收件箱中提取所有电子邮件,而我只想要特定电子邮件的回复。这是我的实际代码:*使用message_id保存电子邮件*mail=gmail.deliver(email)Email.create(:message_id=>mail.message_id,:from=>user.email,:to=>annotation.to,:body=>annotation.content,:title=>annotation.title,:annotation=>an

ruby-on-rails - Ruby on Rails 3: Devise::LdapAdapter.get_ldap_param 未定义方法错误

我正在运行:ruby1.9.3p0,rails3.1.1,设计1.4.9,Devise_ldap_authenticatable0.4.10我正在使用Devise通过ldap服务器验证我的Rails应用程序。我使用用户名而不是电子邮件进行身份验证,所以我表中的电子邮件字段自然是空白的。在ldap中查询email,官方的做法是在用户模型中加入这段代码:before_save:get_ldap_emaildefget_ldap_emailself.email=Devise::LdapAdapter.get_ldap_param(self.username,"mail")end这段代码失败了

ruby-on-rails - 无方法错误 : undefined method `get' when running rspec and making get/visit calls

我完全被困在这里,希望有人能指出我正确的方向。我正在尝试使用rspec来测试我的网络路由。我按照这里的例子:https://www.relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec我的规范文件被命名为:spec/requests文件夹中的api_tests_spec.rb。文件如下:require'spec_helper'describe"APITests"dodescribe"GET/regions"doit"shouldreturnavalidresponse"do#Runthegeneratoragai

ruby-debug19 : Can't get working with Ruby 1. 9.1p376

我正在尝试将ruby​​-debug19与Ruby1.9.1p376一起使用,但出现以下错误:test.rb:2:in`require':nosuchfiletoload--ruby-debug19(LoadError)fromtest.rb:2:in`'这是测试.rb:require'rubygems'require'ruby-debug19'这是“gemlist”的输出:***LOCALGEMS***ruby-debug19(0.11.6)(etc.)因此运行“rubytest.rb”会产生上述错误。我做错了吗?我认为这是运行ruby​​-debug19的正确方法(通过包含gem并

ruby-on-rails - Rails 中的 Post Redirect Get 模式

如何在Rails中实现PRG?我在Rails中使用了PRG,但我并不完全相信它是正确的。我想知道在Rails中是否有更好的方法来处理它? 最佳答案 我不知道PRG模式有多流行以及为什么人们必须虔诚地坚持它的失败方面的“重定向”(实际上,一个很好的理由是有时你不想处理“设置”的复杂性制造失败并保持干燥)。您基本上需要的是将:user的参数传输到new。我认为上面@Hitesh的解决方案非常接近。classUsersController:newendendend 关于ruby-on-rail

ruby-on-rails - "554 Please activate your Mailgun account. Check your inbox or log in to your control panel to resend the activation email."错误 Ruby on Rails

我正在使用RubyonRails构建网络应用程序。我正在使用Mailgun作为这个应用程序的邮件程序。当我使用Facebook注册时它工作正常但是当我尝试使用电子邮件和密码注册时,我不断收到此错误“554请激活您的Mailgun帐户。检查您的收件箱或登录到您的控制面板以重新发送激活电子邮件。“我已经在mailgun仪表板中将eamil授权给授权收件人。这是我的代码:Registrations_controller.rbclassRegistrationsControllerconfig/environments/development.rbRails.application.confi

ruby - Heroku,设计 : Getting 'NoMethodError (undefined method ` to_key' for :user:Symbol)'

我不知道它是什么时候发生的,但我收到了这个错误NoMethodError(undefinedmethod'to_key'for:user:Symbol)此行为仅发生在HerokuCedar堆栈上。我使用Devise(1.4.2)通过FacebookonRails3.1.0.rc6和ruby​​1.9.2-p290进行身份验证。它发生在sign_in_and_redirect(:user,authentication.user)行。这是我的方法:defcreateomniauth=request.env['omniauth.auth']authentication=Authenticat

ruby (在 Rails 上)正则表达式 : removing thousands comma from numbers

这看起来很简单,但我遗漏了一些东西。我有大量来自各种来源和不同格式的输入。数字输入123123.45123,45(notethecommausedheretodenotedecimals)1,2341,234.5612,345.6712,345,67(notethecommausedheretodenotedecimals)关于输入的附加信息数字永远小于100万编辑:这些是价格,因此要么是整数,要么是百分之一我正在尝试编写一个正则表达式并使用gsub去除千位逗号。我该怎么做?我写了一个正则表达式:myregex=/\d+(,)\d{3}/当我在Rubular中测试它时,它表明它只在我想