草庐IT

something_that_does_not_exist

全部标签

ruby-on-rails - Ruby:Class.new 在 Rails 控制台中给出 "Class not initialized"错误

我正在创建一个轻量级应用程序来创建和显示即将发生的事件的信息。我定义了一个Event类,它将args散列作为参数。初始化方法定义如下。classEvent到目前为止,还不错。然后,在Rails控制台中,我定义了一个args散列并尝试创建一个Event实例,但出现以下错误。[4]pry(main)>args={what:'what',theme:'theme'}=>{:what=>"what",:theme=>"theme"}[5]pry(main)>Event.new(args)=>#这看起来很简单,但我很难理解。任何帮助表示赞赏。 最佳答案

ruby-on-rails - 参数错误 : Factory not registered

我正在尝试使用FactoryGirl运行rspec,但我一直收到此错误:1)ProductsUpdatewithinvalidinformationFailure/Error:let(:product){FactoryGirl.create(:product)}ArgumentError:Factorynotregistered:product#./spec/requests/products_spec.rb:47:in`block(3levels)in'#./spec/requests/products_spec.rb:52:in`block(3levels)in'-这是有错误的测试

ruby - 如何处理 Nokogiri 中的 404 not found 错误

我正在使用Nokogiri来抓取网页。很少有url需要被猜测,当它们不存在时返回404notfound错误。有没有办法捕获这个异常?http://yoursite/page/38475#=>pagenumber38475doesn'texist我尝试了以下方法,但没有用。url="http://yoursite/page/38475"doc=Nokogiri::HTML(open(url))dobeginrescueException=>eputs"Tryagainlater"endend 最佳答案 它不起作用,因为您没有拯救在发现

ruby-on-rails - 如何将条件 "IS NOT NULL"添加到 Thinking Sphinx 搜索中

我正在使用ThinkingSphinx进行全文搜索,关注thisvideo.我想做以下事情:@articles=Article.search(params[:search],:conditions=>"published_atISNOTNULL",:order=>:created_at)问题是这行不通。搜索方法似乎只接受散列条件。我尝试了几种方法,但我对如何将“published_atISNOTNULL”表示为哈希一无所知... 最佳答案 在Railscasts给出了解决方案Ifyouwant*all*resultsforthatm

ruby-on-rails - PGError : ERROR: relation "table_name" does not exist

我正在尝试将一个简单的应用程序推送到heroku并运行:herokurakedb:migrate但是我得到以下错误:rakeaborted!PGError:ERROR:relation"posts"doesnotexist:SELECTa.attname,format_type(a.atttypid,a.atttypmod),d.adsrc,a.attnotnullFROMpg_attributeaLEFTJOINpg_attrdefdONa.attrelid=d.adrelidANDa.attnum=d.adnumWHEREa.attrelid='"posts"'::regclass

ruby-on-rails - Rails 3.1 和 Ruby 1.9.3p125 : ruby-debug19 still crashes with "Symbol not found: _ruby_threadptr_data_type"

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:ruby-debugwithRuby1.9.3?我听说ruby​​1.9.3p125有解决ruby​​-debug19问题的传言,所以根据RVM站点上的说明,我重新安装了1.9.3:$rvmreinstall1.9.3--patchdebug--force-autoconf$ruby-vruby1.9.3p125(2012-02-16revision34643)[x86_64-darwin11.2.0]然后:geminstallruby-debug19将此条目添加到我的Gemfile中:gem'ruby-de

ruby - 英雄数据库 :pull does not work?

我收到以下错误消息:herokudb:pull--debugpostgres://USERNAME:PASSWORD@localhost/testLoadedTapsv0.3.23Warning:Datainthedatabase'postgres://USERNAME:PASSWORD@localhost/test'willbeoverwrittenandwillnotberecoverable.ReceivingschemaUnabletofetchtablesinformationfromhttp://heroku:foo9dsfsdfsdb465ar@taps19.heroku

ruby - 背包 : how to add item type to existing solution

我一直在使用动态规划的这种变体来解决背包问题:KnapsackItem=Struct.new(:name,:cost,:value)KnapsackProblem=Struct.new(:items,:max_cost)defdynamic_programming_knapsack(problem)num_items=problem.items.sizeitems=problem.itemsmax_cost=problem.max_costcost_matrix=zeros(num_items,max_cost+1)num_items.timesdo|i|(max_cost+1).ti

ruby-on-rails - 工厂女孩/Rspec - "Trait Not Registered"错误

跟随BenWalker的(惊人的)Let'sBuildInstagramWithRails,特别是BDD版本。教程使用FactoryGirl。我在多次测试中遇到以下错误:精简版Failure/Error:post=create(:post,user_id=user.id)ArgumentError:Traitnotregistered:1我什至无法让Ben用cloneofmyrepo重新创建错误,我在StackOverflow的“特征未注册”问题中找不到任何内容。这是我的第一个SO问题,所以如果我在那个前面做错了什么,请告诉我。在此先感谢您的帮助!代码选择:spec/factories

ruby-on-rails - ruby rails : Properly creating a model instance that has relation to multiple models

假设我有一个独立的用户模型和服务模型。我还有一个订单模型,用于保存用户为某项服务创建的订单。我想知道如何在Rails中正确创建订单条目。以下是我将如何创建一个订单条目,如果它只引用一个其他模型,比如用户。@order=current_user.orders.build(params[:order])@order.save现在,如果订单涉及多个模型(用户和服务),我该怎么做?假设Order模型具有user_id和service_id属性,并且所有模型对象都正确标记了belongs_to和has_many关系。 最佳答案 @order=