草庐IT

optional_argument

全部标签

ruby-on-rails - 未定义的方法 "apply_finder_options"

我有一个未定义的方法错误“apply_finder_options”_question.html.erb以及错误所在defself.unsolved(params)where(solved:false).paginate(page:params[:page],order:'created_atDESC',per_page:3)enddefself.search(params)问题Controllerdefshowputsparams@question=Question.find(params[:id])@answer=Answer.newend完整的错误堆栈跟踪activerecord

sql - 如何在 :conditions argument to ActiveRecord. 查找中使用 %?

我正在尝试执行这样的查询:Widget.find(:all,:conditions=>["namelike%awesome%"])但是,我从sanitize_sql中收到“格式错误的字符串”异常,将“%”指定为问题。如何执行此查询? 最佳答案 试试这个语法:term="awesome"Widget.all(:conditions=>["nameLIKE?","%#{term}%"]) 关于sql-如何在:conditionsargumenttoActiveRecord.查找中使用%?,我

ruby-on-rails - 类型错误 : wrong argument type Class (expected Module) with Controller concern

所以我有一个名为guests_controller.rb的Controller,如下所示:classGuestsController而且我在controllers/concens/中还有一个名为data.rb的问题:moduleDataextendActiveSupport:Concerndefsave_data(save_method)casesave_methodwhen"db"@guest=Guest.new(guest_params)if@guest.saveflash[:success]="Newguestentrycreated!"redirect_toguests_pat

sql - Rails ActiveRecord Arels : Unsupported argument type: String. 改为构造一个 Arel 节点

我正在使用Arels创建查询。在此查询中,我使用了generate_series函数。这是我的代码:defgenerate_seriesArel::Nodes::NamedFunction.new('GENERATE_SERIES',[start_date,end_day,'1day'])enddefstart_dateArel::Nodes::SqlLiteral.new(当我尝试通过generate_series.to_sql进行测试时。我遇到异常:Arel::Visitors::UnsupportedVisitError:Unsupportedargumenttype:Strin

ruby-on-rails - ruby - 未定义的方法 `extract_options!' : Array

使用TweetStream运行以下示例时我收到错误提示。tweets.rbrequire'tweetstream'TweetStream.configuredo|config|config.consumer_key=''config.consumer_secret=''config.oauth_token=''config.oauth_token_secret='错误$rubytweets.rb/home/amit/.rvm/gems/ruby-1.9.3-p194/gems/tweetstream-2.3.0/lib/tweetstream/client.rb:96:in`track

ruby-on-rails - Ruby on Rails 中 options.dup 的用途是什么?

浏览Rails代码库时,我发现了大量对options.dup的引用。defto_xml(options={})require'builder'unlessdefined?(Builder)options=options.dup....end显然options.dup正在复制选项散列,但为什么要在这种情况下这样做? 最佳答案 dup克隆一个对象。当您将对象传递给方法时,任何更改该对象内部状态的内容都将反射(reflect)在调用范围中。例如,试试这段代码:defreplace_two(options)options[:two]="hi

ruby-on-rails - 我如何解决 "bad argument (expected URI object or URI string)"? Ruby on Rails,Michael Hartl 教程

我正在关注RubyonRailsTutorial作者:MichaelHartl。我到达了Chapter11.37但我的测试失败了。我收到以下错误:Failure/Error:xhr:post,:create,relationship:{followed_id:other_user.id}ArgumentError:badargument(expectedURIobjectorURIstring)我是RubyonRails的新手,所以我真的不知道出了什么问题。有人可以帮助解决此错误吗?controllers/relationships_controller.rb:classRelatio

ruby - gem 安装失败,显示 "ruby: invalid option -H (-h will show valid options) (RuntimeError)"

在OSXMountainlion上运行geminstallffi会产生以下错误。geminstallffiBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingffi:ERROR:Failedtobuildgemnativeextension./beweiche.rvm/rubies/ruby-1.9.3-p374/bin/rubyextconf.rb/beweiche.rvm/rubies/ruby-1.9.3-p374/bin/ruby:invalidoption-H(-hwillshowvalido

ruby - 是否可以结合 with_options 和 :if for conditional validations?

我正在尝试使用with_options为管理员用户将我的条件验证组合在一起。对用户名唯一性的第二次验证最终覆盖了with_options条件。有更好的方法吗?或者我应该忘记with_options并编写两个单独的语句?with_options:if=>Proc.new{|user|user.admin?}do|admin|admin.validates:email,:presence=>trueadmin.validates:username,:uniqueness=>true,:if=>Proc.new{|user|user.category=="customized_usernam

ruby-on-rails - FactoryGirl 问题 - `factory' : wrong number of arguments (0 for 1) (ArgumentError)

我正在学习RubyonRails教程,我已经接近尾声了,但是FactoryGirl并没有让我轻松完成。我无法运行任何需要工厂的规范文件。require'spec_helper'require'factory_girl_rails'describeUserdobefore(:each)do@attr={:name=>"ExampleUser",:email=>"user@example.com",:password=>"foobar",:password_confirmation=>"foobar"}endit"shouldcreateanewinstancegivenvalidattr