草庐IT

date_of_post

全部标签

ruby - GET 和 POST 请求的相同 Rails 4 路由

在Rails3中,Match用于指向“GET”和“POST”以及其他类型请求的操作。match"user/account"=>user#account现在这将指向用户Controller对GET和POST请求的帐户操作。由于在Rails4中“匹配”已被弃用,我们可以在Rails4中为GET和POST创建相同的路由吗? 最佳答案 Fromthematchdocumentation,你可以使用match只要你有via:match"user/account"=>"user#account",as::user_account,via:[:g

ruby-on-rails - 什么是 Post.all.map(& :id) mean?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Whatdoesmap(&:name)meaninRuby?Post.all.map(&:id)会回来=>[1,2,3,4,5,6,7,................]map(&:id)是什么意思?特别是&。

ruby-on-rails - 测试 : how to focus on behavior instead of implementation without losing speed?

似乎有两种完全不同的测试方法,我想引用它们。问题是,这些意见是在5年前(2007年)提出的,我很感兴趣,从那以后发生了什么变化,我应该走哪条路。BrandonKeepers:Thetheoryisthattestsaresupposedtobeagnosticoftheimplementation.Thisleadstolessbrittletestsandactuallyteststheoutcome(orbehavior).WithRSpec,Ifeellikethecommonapproachofcompletelymockingyourmodelstotestyourcontr

ruby-on-rails - 类型错误 : no implicit conversion of Symbol into Integer

我在尝试更改散列的值时遇到了一个奇怪的问题。我有以下设置:myHash={company_name:"MyCompany",street:"Mainstreet",postcode:"1234",city:"MyCity",free_seats:"3"}defcleanupstringstring.titleizeenddefformatoutput=Hash.newmyHash.eachdo|item|item[:company_name]=cleanup(item[:company_name])item[:street]=cleanup(item[:street])output当我

ruby-on-rails - Ruby 1.87 与 1.92 Date.parse

在Ruby1.87中我可以这样做:Date.parse("3/21/2011")现在在1.9.2中我得到:ArgumentError:invaliddate有什么想法吗? 最佳答案 使用strptime并给出特定的时间格式。ruby-1.9.2-p136:022>Date.strptime'03/21/2011','%m/%d/%Y'=>#参见michaelmichael'sresponseRuby版本之间存在这种差异的原因。 关于ruby-on-rails-Ruby1.87与1.92D

ruby - 强制 bundle 安装使用 https ://instead of git://for GitHub-based gems

我正在尝试构建一个Rails项目,因为我正在使用的主机无法访问Internet的git://协议(protocol)(端口9418),我收到如下错误Fetchinggit://github.com/pivotal/jasmine.gitfatal:unabletoconnecttogithub.com:github.com[0:192.30.252.130]:errno=Connectionrefused运行bundleinstall时。GemFile中的相关行没有指定git://作为协议(protocol),它只是指向GitHub作为gem的源gem'jasmine',:github

ruby-on-rails - 将 POST 数据从 Controller 提交到 Rails 中的另一个网站

用户提交包含一些基本数据的表单。数据由Controller中的操作接收和处理,并添加更多需要保密的信息。然后我需要向外部网站发送一个post请求,其中包含来自Controller的所有组合数据。执行此操作的最佳方法是什么? 最佳答案 最简单的方法是使用ruby​​核心库:require"uri"require"net/http"params={'box1'=>'Nothingislessimportantthanwhichforkyouuse.Etiquetteisthescienceofliving.Itembracesevery

ruby - 警告 : Can't verify CSRF token authenticity in case of API development

我现在正在使用RubyonRails开发网络API。当Rails应用程序收到没有任何csrftoken的POST请求时,将出现以下错误消息。因为该应用没有View。WARNING:Can'tverifyCSRFtokenauthenticity所以我的问题是在这种情况下如何安全地逃避csrftoken检查?非常感谢您。 最佳答案 你可以通过添加skip_before_filter:verify_authenticity_token到你的Controller。这样,所有传入Controller的请求都会跳过:verify_authen

ruby - 为什么Ruby 的Date 类会自动加载而DateTime 不会?

为什么使用IRB会自动加载Date&Time类,但DateTime类不会?我必须require'date',这对我来说没有意义,因为我认为Date和DateTime都在使用标准库'date'?ruby-1.9.2-p290:001>Date=>Dateruby-1.9.2-p290:002>Time=>Timeruby-1.9.2-p290:003>DateTimeNameError:uninitializedconstantObject::DateTimefrom(irb):3from/Users/kamilski81/.rvm/rubies/ruby-1.9.2-p290/bin/

ruby-on-rails - Rails POST、PUT、GET

生成脚手架后,Rails使我能够POST到items.xml,这将创建一个新的item。对items.xml的GET将简单地将它们全部列出。根据我正在执行的操作类型,Rails在哪里指定将调用Controller中的哪个方法(分别为create或index)?更具体地说,POST调用方法A,但GET到相同的URL调用方法B。这是在哪里指定的?Rails在哪里判断调用Controller的index方法? 最佳答案 我相信它是由REST指定的.这是给你的list:GET/items#=>indexGET/items/1#=>showG