草庐IT

method_idx

全部标签

ruby-on-rails - rails : Where do I put my API methods?

我是Rails的新手,在做一些简单的事情(例如创建API调用)时我有点不知所措。我在/reports设置了一个路由,它有这个Controller:classReportsController1})step1_result=step1.parseputs"Done!"putsstep1_resultrescueExcon::Errors::ServiceUnavailable=>eputs"Didn'twork"logger.warne.response.messageretryendend#Endrequest_reportrequest_reportend当我第一次加载/report

ruby - 为什么我的 define_method 内容在类范围内被评估?

我正在做一些(太)花哨的元编程,我很难理解为什么在以下两种情况下范围不同:案例1:classTesterAdefthe_methodputs"I'maninstance_method!"enddefself.the_methodputs"I'maclass_method!"enddefself.define_my_methods*method_namesmethod_names.eachdo|name|define_method("method_#{name}")dothe_methodendendenddefine_my_methods:a,:b,:cendt=TesterA.new

ruby - 如何从 method_missing 获取绑定(bind)?

我试图找到一种方法来在Ruby(1.8)的method_missing中从调用者那里获取绑定(bind),但我似乎无法找到实现它的方法。希望下面的代码能解释我想做什么:classAdefsome_methodx=123nonexistent_methodenddefmethod_missing(method,*args,&block)b=caller_binding#那么...有没有办法获得调用者的绑定(bind),或者这在Ruby(1.8)中是不可能的? 最佳答案 这是一个(有点脆弱的)hack:#caller_binding.r

ruby-on-rails - rails 小号 : undefined method `symbolize_keys'

关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。这个问题似乎与helpcenter中定义的范围内的编程无关。.关闭9年前。Improvethisquestion我有一个Rails3.2.12应用程序,但是当我运行railss时,我收到以下错误:connection_specification.rb:45:in'resolve_hash_connection':undefinedmethod'symbolize_keys'for#(NoMethodError)connection_specification.rb相关方法:defresolve_has

ruby-on-rails - Rspec NoMethodError : undefined method `call' , 但一切都通过 rails 控制台工作

我是一个正在努力学习的rails/rspec新手。我设置了以下数据模型(摘录)t.string:foot.string:bart.date:future_date我有一个Web表单来创建这些与用户关联的条目,类似于此railstutorial中的微博.Web表单如下所示(摘录):带有启动帖子的“创建”按钮。通过railsconsole似乎一切正常;Web表单显示正确,条目创建正确,数据库正确填充。但是,当我运行rspec时,我得到了NoMethodError:undefinedmethod`call'for#这是相关的请求规范(摘录):it"shouldnotcreateafoobar

ruby - 无方法错误 : undefined method `+@' for "some sting":String

我的Rails应用程序今天才开始收到此错误。这是代码上下文。它在以new_host_id开头的行上抛出错误while@host_ids.include?(new_host_id)i++new_host_id=duplicate_host_id+i.to_send 最佳答案 Ruby没有有++操作符。Ruby中的成语是i+=1,是i=i+1的缩写形式。最初我认为发布的代码不正确,必须是++i才能生成该错误。然而,正如JörgWMittag在评论中解释的那样,情况并非如此:[..]Rubyallowswhitespace(includi

ruby-on-rails - delayed_job : 'undefined method' error when using handle_asynchronously

我正在尝试使用delayed_job将更大的csv导入到我的rails数据库中。这是我的Controller和模型方法:Controller方法defimportInventoryItem.import(params[:file],params[:store_id])redirect_tovendors_dashboard_path,notice:"InventoryImported."end模型方法defself.import(file,store_id)CSV.foreach(file.path,headers:true)do|row|inventory_item=Inventor

ruby-on-rails - rails : how to exclude one item from an "each" method

我正在使用Enki博客gem作为一种内容管理系统。它允许您创建帖子和页面。它会自动生成两个页面(主页和文件)。我还创建了另外两个示例页面,服务和产品,并将创建更多。因此,当我想列出主页上的所有页面时,我这样做HomeArchivesServicesProducts我以后可能想创建更多页面,所以最好像这样遍历所有页面,而不是对每个页面的url进行硬编码。但是如果我想排除其中一个页面(即文件),我将如何更改该代码。Enki会自动生成该页面并且不给我删除它的选项。而且,我不想删除存档,因为我想在发布博客文章链接的地方使用它。因此,简而言之,我如何从该代码中排除一个特定页面Archives的u

ruby-on-rails - rails 上的 ruby : start_form_tag method

我正在尝试学习ruby​​onrails。我一直在学习教程,但我被卡住了。它让我使用start_form_tag和end_form_tag围绕一个输入表单。但是,当我访问该页面时,我得到undefinedmethod'start_form_tag'for#在教程中,他们解释说这两行被翻译成和.因此,我尝试将它们放在一起。表格出来了,但是当我提交表格时,我得到这个错误:ActionController::InvalidAuthenticityTokeninBookController#create所以,我需要做什么才能让start_form_tag正确翻译?这是导致InvalidAuth

ruby - ruby中定义的method_missing在哪里

我使用ruby​​-1.9.3。当method_missing方法来的时候,我试图找出这个方法是在哪里定义的。我看了一下RubyDoc,发现方法是在BasicObject中定义的,但是当我在irb中使用BasicObject.methods.grep/^method/时,它给了我一个没有任何method_missing方法的结果数组,然后,我尝试了Kernel。methods.grep/^method/,但仍然没有method_missing方法。你能帮帮我吗?我在哪里可以找到这个方法? 最佳答案 使用Method#owner知道在