Tag: migrate

使用Rails将外部JSON保存到DB

我正在使用gem“httparty”对外部源进行GET调用; 这是我的Controller.rb: def show response = HTTParty.get(‘URI’) user = JSON.parse(response) user.each {|line| puts line[‘user’][‘id’]} #the “[‘user’][‘id’]” is because of the nested JSON object that is returned after the parse. end 这会在我的rails控制台中返回正确的输出,但现在的问题是如何将[‘id’]保存到我的数据库中? 目前,我的用户模型有:id和:name; 来自外部API的JSON对象发送:id和:name以及一些我不需要的其他信息。 class User < ActiveRecord::Base attr_accessor :id, :name end 任何帮助表示赞赏,谢谢!

Rails mysql2 undefined方法`accept’代表nil:NilClass

我知道这是一百万次,但尝试了一切,我仍然得到这个错误: $ rake db:migrate rake aborted! undefined method `accept’ for nil:NilClass Tasks: TOP => db:migrate (See full trace by running task with –trace) 这是gem列表(不是全部): activemodel (3.2.8) activerecord (3.2.8) activerecord-mysql2-adapter (0.0.3) builder (3.1.3, 3.0.3) bundler (1.2.1) mysql2 (0.3.2) rails (3.2.8) rails_apps_composer (2.2.10) railties (3.2.8) rake (0.9.2.2) rdoc (3.12) sqlite3 (1.3.6) therubyracer (0.10.2) thor (0.16.0) tilt (1.3.3) […]