jjzjj

json_name

全部标签

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 - 未初始化常量 "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 - 如何测试 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-on-rails - 未定义的方法 `name' 为 "actionmailer":String

我有一个旧版本的Rails项目,它是使用BrowserCMS构建的在配置/环境文件中RAILS_GEM_VERSION='2.3.4'unlessdefined?RAILS_GEM_VERSION所以我使用rvm安装了这个gems,所以我可以运行它$gemlist***LOCALGEMS***actionmailer(2.3.8,2.3.4)actionpack(2.3.8,2.3.4)activerecord(2.3.8,2.3.4)activeresource(2.3.8,2.3.4)activesupport(2.3.8,2.3.4)bundler(1.1.4)mysql(2.8

ruby-on-rails - 在带有 HTTPParty 的 Controller 中解析 JSON

在我的Controller中,我有以下代码...response=HTTParty.get('https://graph.facebook.com/zuck')logger.debug(response.body.id)我收到一个NoMethodError/undefined方法`id'如果我这样做...logger.debug(response.body)它按预期输出...{"id":"4","name":"MarkZuckerberg","first_name":"Mark","last_name":"Zuckerberg","link":"http:\/\/www.faceboo

ruby - 获取名称错误 : `format' is not allowed as an instance variable name when testing instance variable with rspec

我有以下测试:let(:client){Descat::Client.new}describe'poblacio'doit'shouldsetformatcorrectly'doclient.poblacio('v1','json','dades')expect(client.instance_variable_get(:format)).toeq('json')endend我有以下正在测试的代码:moduleDescatclassClientBASE_URL='http://api.idescat.cat/'definitialize(attributes={})attributes

ruby-on-rails - will_paginate JSON 支持?

我想知道是否有人可以告诉我will_paginate是否可以开箱即用地支持JSON,或者是否必须对其进行破解?我想将页面数据添加到JSON响应中,而will_paginate管理分页。 最佳答案 内容如下:@posts=Post.paginate:page=>params[:page]respond_todo|format|format.json{render:json=>{:current_page=>@posts.current_page,:per_page=>@posts.per_page,:total_entries=>@p

Ruby:使用 JSON 正文 PUT 请求?

我需要使用ruby​​创建一个HTTPPUT请求。请求有一个JSON正文我能够使用以下方法生成JSON正文:require'rubygems'require'json'jsonbody=JSON.generate["message"=>"test","user"=>"user1"]我需要将此PUT请求发送到url:require'open-uri'url=URI.parse('http://www.data.com?access_token=123')谁能告诉我如何在Ruby中做到这一点? 最佳答案 像这样使用restclient(

ruby-on-rails - 如何让 Rails 中的 named_scope 返回一个值而不是数组?

我想写一个namedscope从它的id中获取记录。例如,我有一个名为Event的模型,我想使用named_scope来模拟Event.find(id)future的灵active。我在我的模型中使用了这段代码:named_scope:from_id,lambda{|id|{:conditions=>['id=?',id]}}我从我的Controller调用它,如Event.from_id(id)。但我的问题是它返回一组Event对象而不是一个对象。因此如果我想获取事件名称,我必须写event=Event.from_id(id)event[0].name而我想要的是event=Even

ruby - 在 ruby​​ 中将 .json 转换为 .csv

我想使用ruby​​将.json文件转换为.csv文件。请帮我做这件事。同时提出实现此目的的任何工具。 最佳答案 尝试这样的事情:require'csv'require'json'csv_string=CSV.generatedo|csv|JSON.parse(File.open("foo.json").read).eachdo|hash|csv 关于ruby-在ruby​​中将.json转换为.csv,我们在StackOverflow上找到一个类似的问题: