草庐IT

How-do-you-handle-authentication-

全部标签

ruby-on-rails - map(& :name) do in this Ruby code? 是什么意思

为了更好地理解Ruby,我在网上冲浪时遇到了这段代码:require'rubygems'require'activeresource'ActiveResource::Base.logger=Logger.new("#{File.dirname(__FILE__)}/events.log")classEvent"Shortesteventevar!",:starts_at=>1.second.ago,:capacity=>25,:price=>10.00)e.destroy我特别感兴趣的是events.map(&:name)是如何工作的?我看到events是一个数组,因此它调用了它的ma

ruby-on-rails - ruby rails : How to check if the Model Exists

我想知道如何检查模型是否已经存在于项目中?当用户尝试使用相同的模型名称以编程方式创建模型时,需要检查它是否已经存在? 最佳答案 定义了吗?如果模型已定义,ModelName将返回“常量”。 关于ruby-on-rails-rubyrails:HowtocheckiftheModelExists,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/11793869/

ruby - 导轨 : How do I require NumberHelper and make it work?

我正在尝试编写一个简单的Sinatra东西,但我需要操作包中的ActionView::Helpers::NumberHelper。http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html问题是,如何安装和使用它?irb(main):001:0>require'action_view/helpers/number_helper'irb(main):002:0>number_with_precision(1)NoMethodError:undefinedmethod`number_with_precisi

ruby - 法拉第 : you may want to install system_timer for reliable timeouts

我将一个旧脚本迁移到一个新的CentOSbox并在运行脚本时收到以下消息:Faraday:youmaywanttoinstallsystem_timerforreliabletimeouts它是警告吗?system_timer是什么?gem? 最佳答案 这是一颗gem。不过,您应该不再需要它了,因为它只支持Ruby1.8及更早版本(Ruby1.8已正式弃用)。来自http://ph7spot.com/musings/system-timer:Update:system_timerisonlyrelevantifyouarerunni

ruby-on-rails - 设计/Omniauth 失败 : How to debug it?

尝试“使用Google登录”后,我在日志中看到此错误:ProcessingbyUsers::OmniauthCallbacksController#failureasHTML我可以看到通过URL(在日志中)发送的来自谷歌的所有数据,包括用户电子邮件和姓名。那么会出什么问题呢?我的回调甚至没有被执行。我只会被重定向到我网站的登录页面。而且我很确定一切都配置正确,因为几周前它运行良好。我不认为我改变了什么。Facebook登录仍然正常。关于如何调试此故障的任何想法?除了那些充满参数和值的长URL之外,日志中没有其他内容。只有INFO消息。上面发布的是唯一一个说失败的。更新我向Control

ruby-on-rails - 使用设计上下文的 "super"和 "super do |u|"之间的区别

好吧,我想我得到了什么superdoes独立的。基本上在设计中,如果Users::RegistrationsController,然后在任何行动中,都有一个super将首先调用父级中相同命名操作的逻辑Devise::RegistrationsController,然后调用你写的内容。换句话说...classDevise::RegistrationsControllerdefnewputs"thisisintheparentcontroller"endendclassUsers::RegistrationsController"thisisintheparentcontroller"#=

ruby-on-rails - ruby 中关键字 "do"的含义是什么?

我在Ruby中看到过一些do,但我找不到对其用途的真正好的解释。例如,我看到do的地方是在gemfile中:group:development,:testdogem'rspec-rails'gem'rspec-its'gem'simplecov',:require=>falsegem'guard-rspec'gem'spork-rails'gem'guard-spork'gem'childprosess'gem'rails-erd'gem'pry-rails'gem'guard-rails'gem'guard-livereload'gem'guard-bundler'end我知道这段代

ruby-on-rails - Elasticsearch /轮胎 : How do I filter a boolean attribute?

我想过滤我类(class)的私有(private)bool值,以便它只显示非私有(private)但对我不起作用的资源。(我大大简化了代码)mappingdoindexes:private,type:"boolean"indexes:name,type:"string"endenddefself.search(params)tire.search(load:true,page:params[:page],per_page:20)doquery{stringparams[:query]}ifparams[:query].present?#SofarI'vetried...#filter:

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 - rails : How do I check if a column has a value?

我怎样才能做到这一点?...Cell:...我想测试代理是否有手机号码,如果有,显示条件中的内容。我目前拥有的似乎不起作用;它只显示“单元格:”。想法? 最佳答案 这是你要求的:Cell:细胞?无论cell是nil还是空字符串,方法都有效。Rails为所有ActiveRecord属性添加了类似的功能。这看起来会好一点:Cell:问号和冒号构成了一个快速的“if?then:else”语句。上面代码中有两个问号是因为一个是方法名单元格的一部分?另一个是if/then/else构造的一部分。