草庐IT

day34-JSON

全部标签

ruby - 在带有 RVM : 的 OS X 上安装 Ruby 1.9.3 时出现 "No available formula for gcc46"

我安装了Homebrew,我正在尝试安装RVM:rvminstall1.9.3-head我得到这个错误:Installingrequiredpackages:gcc46Errorrunning'requirements_osx_brew_libs_installgcc46',pleaseread/Users/mike/.rvm/log/1384918134_ruby-1.9.3-head/package_install_gcc46.logRequirementsinstallationfailedwithstatus:1brewdoctor说我准备好了。在日志中我看到:Error:Do

ruby - 如何避免 RSpec 中的 "Useless use of == in void context"?

在RSpec中,如果我有警告并且有x.should==42another_line_of_code然后我得到一个关于的警告warning:uselessuseof==invoidcontext还有什么我可以做的吗关闭警告将其更改为bitbucket=(x.should==42) 最佳答案 使用:x.shouldeq(42)或者:x.shouldbe==42或者移动x.should==42使其成为itblock中的最后一行。对于那些思考但是为什么?的人我完全是Ruby的菜鸟,但这是我的理解:警告来自Ruby,因为像x.should==

ruby-on-rails - 来自 URL 的 Ruby on Rails 和 JSON 解析器

我使用'gemjson'并需要从一些url加载JSON数据,例如:“http://locallhost:3000/qwerty/give_json.json”与{"one":"Omg","two":125,"three":"Hu"}我有Rails应用程序classQwertyController我得到错误JSON::ParserErrorinQwertyController#get_json795:unexpectedtokenat'http://localhost:3000/qwerty/give_json.json'在字符串中:@data=JSON.parse(JSON.load(

ruby-on-rails - 使用 Rails 中的命名空间类防止 "warning: toplevel constant B referenced by A::B"

在自定义目录(例如:app/presenters/)中存储文件时,如何确保加载命名空间类?例如,如果您有:app/models/mega_menu.rbapp/presenters/catalog_presenter.rbapp/presenters/mega_menu/catalog_presenter.rbRails无法加载MegaMenu::CatalogPresenter:CatalogPresenter.new=>#MegaMenu::CatalogPresenter.new(irb):3:warning:toplevelconstantCatalogPresenterref

ruby-on-rails - Rails,如何避免 "N + 1"查询关联中的总数(计数、大小、counter_cache)?

我有这些模型:classChildren我现在需要的是在“电影院”的页面中,我想为那个电影院的电影打印children的总和(数量,大小?),所以我这样写:在cinemas_controller.rb中:@childrens=@cinema.childrens.uniq在cinemas/show.html.erb:但显然我有bulletgem提醒我Counter_cache并且我不知道把这个counter_cache放在哪里因为电影的不同id。而且在没有counter_cache的情况下,我所拥有的也不是我想要的,因为我想要计算该电影院中有多少child从该电影院许多天的门票中拿走了他

ruby - "do | |"在 Ruby 中是什么意思?

在阅读一些Ruby代码时,我看到了这个:create_table:talksdo|t||variable|这个符号是什么?那有什么作用?此外,我在哪里可以找到这些特定主题的帮助,例如||、#{}等等? 最佳答案 这是一种为block定义参数的方法,类似于defmethodname(arg1,arg2)有一个很好的block解释fromRobertSosinski 关于ruby-"do||"在Ruby中是什么意思?,我们在StackOverflow上找到一个类似的问题:

ruby-on-rails - 未初始化常量 "Controller Name"

我的路由/资源和Controller有错误。我在routes.rb中有以下内容:#routes.rbresources:usersdoresource:scheduleend我在controllers/users/中设置了一个schedule_controller.rb,我认为它应该是:classUsers::ScheduleController运行rake:routes显示user_schedulePOST/users/:user_id/schedule(.:format)schedules#createnew_user_scheduleGET/users/:user_id/sche

Ruby "return unless nil"成语

我有一个臭臭的方法,比如:defsearch_record(*args)record=expensive_operation_1(foo)returnrecordunlessrecord.nil?record=expensive_operation_2(foo,bar)returnrecordunlessrecord.nil?record=expensive_operation_3(baz)returnrecordunlessrecord.nil?record=expensive_operation_4(foo,baz)returnrecordunlessrecord.nil?end“

ruby - 如何测试 JSON REST API

我是ruby​​的新手(第一天使用ruby​​)所以请原谅任何新手问题和缺乏理解。我正在尝试验证对http标注的响应。例如,假设端点如下:https://applicationname-api-sbox02.herokuapp.com而且,我正在尝试通过发送这样的获取请求来验证用户身份:get_response=RestClient.get("https://applicationname-api-sbox02.herokuapp.com/api/v1/users",{"Content-Type"=>"application/json","Authorization"=>"token4

ruby - 如何修复 "Unknown ruby interpreter version (do not know how to handle): RUBY_VERSION."

今天我只想在我的Mac上设置一个jekyll博客,并且已经安装了ruby​​2.3.0,但是当make'$jekyllserve'时,它是错误的。并在终端中显示:错误信息:Unknownrubyinterpreterversion(donotknowhowtohandle):RUBY_VERSION. 最佳答案 看起来像bundleexecjekyllnew将使用以下行创建一个GemfilerubyRUBY_VERSION我相信您会希望将该文件编辑为例如ruby'2.1.1' 关于rub