草庐IT

Sign-in-with-Google

全部标签

ruby-on-rails - respond_with 无法在 ruby​​ on rails 中工作。为什么?

我有一个名为join的post方法,它应该执行以下操作:1)创建一个新对象2)以json对象响应这是我的代码:classGameControllerparams[:name])@p.save!respond_with({:uuid=>@p.uuid})endend出于某种原因,respond_with调用总是失败并出现以下错误:undefinedmethod`model_name'forNilClass:Class如果我将respond_with调用更改为更简单的方法,我仍然会收到错误,例如:respond_with"hello"产生这个错误:undefinedmethod`hello

ruby - 如何授权使用 google-api-ruby-client

我正在为ruby​​使用googleapi,但不知道如何开始,请给我一个ABC示例,非常感谢? 最佳答案 如果您要创建服务帐户应用程序以访问GoogleAnalytics。通过https://code.google.com/apis/console向Google注册.在APIAccess选项卡上,单击CreateclientID,选择ServiceAccount。存储Google将生成的key文件,并记住该key的密码。这里有一些代码可以帮助您入门require'rubygems'require'google/api_client'

ruby-on-rails - rails : replacing try with the Null Object Pattern

在我的大多数应用程序中,我都有一个current_user方法。为了避免像current_user.name这样的情况出现异常,其中current_user是nil,rails提供了try方法。这个问题是我需要记住在current_user可能是nil的地方使用try。我想使用NullObject模式来消除这种额外的开销。classNullUserdefmethod_missing(method_name,*args)nilendenddefcurrent_userreturnNullUser.newunlessUserSession.find@current_user||=UserS

ruby - key : value vs key :value in ruby?

在联想中,我们通常做a:b(belongs_to:something)。当我们使用符号键创建散列时,我们通常会执行a:b。话虽如此,我的问题是这两种语法之间有什么区别。还有什么逻辑可以记住什么时候使用哪个约定? 最佳答案 这与约定无关,与语法有关。:something是Symbol.belongs_to:something是一种被发送到隐式self的方法,同时也省略了括号。我们可以将其写成如下所示:self.belongs_to(:something):something因此只是传递给方法belongs_to的参数。在Hash中,我

ruby-on-rails - 如何匹配YYYY-MM-DDThh :mm:ssTZD timezone format in ruby

我想检查在ruby​​中输入的日期的iso8601格式,比如start_date="2011/05/05"应该匹配2011-05-05T00格式:00:00-04:00并相应地返回错误。我们应该在这里使用正则表达式还是为此提供任何方法? 最佳答案 听起来像你想要的Time.iso8601:require'time'iso=Time.iso8601(start_date)参见thisblogpost获取更多信息。编辑:这是一个简短但完整的有效测试程序:require'time'text="2011-05-05T00:00:00-04:

ruby-on-rails - #<ProjectsController :0x007faead1853e0> 的未定义方法 `user_signed_in?'

我想用RubyonRails进行身份验证,每个用户都有自己的帐户。但是现在我得到了这个错误:undefinedmethoduser_signed_in?for#有人能帮帮我吗?代码如下:完整跟踪:app/controllers/projects_controller.rb:69:in`require_login'activesupport(3.2.3)lib/active_support/callbacks.rb:418:in`_run__2505248868868045404__process_action__114470166732456289__callbacks'actives

ruby - 轨道 4 log4r server.rb :78:in `start' : undefined method `formatter'

我已经研究这个话题太久了,所以我必须发布这个。我有几个运行此设置的应用程序,其中一个在rails启动(railss)时完全失败。它们的配置几乎完全相同,但我似乎无法在这里大海捞针。有没有人对如何找到这个问题有任何指示?设置基于:http://blog.mmlac.com/log4r-for-rails/comment-page-1/#comment-1731当我尝试运行railss时:=>BootingWEBrick=>Rails4.0.0applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Run`railsserver-h`f

ruby-on-rails - 在 Ruby on Rails 中访问 Google Drive 电子表格

我正在尝试获取GoogleDrive电子表格的内容,但我似乎找不到可以轻松完成此操作的gem。我试过google-drive-ruby,但它涉及一个步骤,我必须从Google的网站获取授权token。这不是很有帮助,因为我必须在服务器端完成所有这些工作。显然在以前版本的gem中有一个登录方法,但被删除了。有什么办法吗?我必须使用OAuth吗?获取token并将该token传递到google-drive-ruby? 最佳答案 我设法在Reddit上得到了答案。您需要一个服务帐户并与您的服务应用程序的电子邮件共享文档。p12key也必须

ruby - Chef : Can a variable set within one ruby_block be used later in a recipe?

假设我有一个变量directory_list,我在名为get_directory_list的ruby​​_block中定义和设置了它。我可以稍后在我的Recipe中使用directory_list吗,或者编译/收敛过程会阻止这种情况吗?例子:ruby_block"get_file_list"doblockdotransferred_files=Dir['/some/dir/*']endendtransferred_files.eachdo|file|file"#{file}"dogroup"woohoo"user"woohoo"endend 最佳答案

ruby - Delayed_job : how to use handle_asynchronously to work with a function?

函数是:defcreateuser(name,pass,time)putsname,pass,timeend我试试:handle_asynchronously:createuser("a","b","c")得到一个错误:语法错误,意外'(',期待keyword_end谢谢。===编辑===日本的用户数据库和北京的网络服务器。所以我用这种方式来创建用户。defcreateuser(name,pass,time)Net::HTTP.get(URI.parse("http://www.example.net/builduser.php?hao=#{name}&mi=#{pass}&da=#{