草庐IT

creating-tray-applications-in

全部标签

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 - 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 - PostsController 中的 NoMethodError#create

请原谅我的无知,但我不仅是Ruby的新手,而且是一般编程的新手。我正在研究ruby​​onrails.org上有关边缘指南的示例。并收到以下错误,尽管检查了自应用程序上次运行以来我输入的每一段代码,但我无法修复它。NoMethodErrorinPostsController#createundefinedmethod`permit'for{"title"=>"","text"=>""}:ActiveSupport::HashWithIndifferentAccess这就是我的posts_controller.rb的样子:classPostsController我做错了什么?提前感谢您的

ruby-on-rails - rails : Find rows without connection in HABTM relation

我有两个模型,Users和Leads与HABTM关系相关:classLead我现在如何才能只获得那些与用户无关的线索?提前致谢! 最佳答案 您正在寻找的是antijoin.有三种标准方法可以实现这一点,使用空左外连接使用带有NOT和IN关键字的子查询的where子句使用带有NOT和EXISTS关键字的where子句基本上,EXISTS关键字将检查子查询是否返回任何行并将其报告为匹配项,NOT显然会否定真正的匹配项。这是我的首选方式(使用NOT&EXISTS)classUser这是一个使用arel的非SQL方法classUserher

ruby-on-rails - ActionView::Template::Error(application.css 未预编译):

我以前在heroku上开发过几个应用程序,从来没有遇到过这个错误:ActionView::Template::Error(application.css未预编译):我最新的推送甚至没有对application.css文件进行更改。这是怎么回事?我看到文章说将production.rb中的一行更改为:#Don'tfallbacktoassetspipelineifaprecompiledassetismissedconfig.assets.compile=true但这不会减慢一切吗?为什么会突然出现这个错误?修复它的最佳方法是什么?编辑:我应该注意到它在开发中工作得很好。

sql - 在 Rails 准备语句语法中使用 WHERE IN

假设我有一个id数组(从客户端接收):myArray=[1,5,19,27]我想返回该列表中(次要)id的所有项目。在SQL中这将是:SELECT*FROMItemsWHEREidIN(1,5,19,27)我知道我可以:Item.where(id:[1,5,9,27]),然而,将其添加到的查询使用准备语句语法的时间越长Item.where('myAttrib=?ANDmyOtherAttrib?ANDmyThirdAttrib=?',myVal[0],myVa[1],myVal[2])考虑到这一点,我想要的是:Item.where('idIN?',myArray)但是,这会产生语法错误

ruby-on-rails - ruby rails : redirect_to not working after create and save

我想在用户提交电子邮件后redirect_toslider_path。当前,仅显示成功消息而没有重定向。这是代码:classSplash::SubscribersController{:success=>success,:message=>message}.to_json}endendend 最佳答案 只需替换这部分代码:ifsuccessflash[:success]=messageredirect_toslider_pathelseflash[:error]=messageendredirect_toroot_path用这个:i

ruby - 通过 gem install mechanize 安装 gems 时显示错误 "invalid switch in RUBYOPT: -F (RuntimeError)"

我尝试通过以下命令在我的计算机上安装gem(Mechanize):>>geminstallmechanize--platform=ruby>>geminstallmechanize错误ERROR:Errorinstallingmechanize:ERROR:Failedtobuildgemnativeextension."C:/ProgramFiles/Ruby200-x64/bin/ruby.exe"extconf.rbC:/ProgramFiles/Ruby200-x64/bin/ruby.exe:invalidswitchinRUBYOPT:-F(RuntimeError)在我尝