Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 整个架构不可用于API调用_Ruby On Rails_Activerecord_Rake_Migrate_Dbmigrate - Fatal编程技术网

Ruby on rails 整个架构不可用于API调用

Ruby on rails 整个架构不可用于API调用,ruby-on-rails,activerecord,rake,migrate,dbmigrate,Ruby On Rails,Activerecord,Rake,Migrate,Dbmigrate,我有一个类,其中我没有从GETAPI调用中获取整个模式 My schema.rb: create_table "jumpsquares", force: true do |t| t.string "name" t.integer "apptype" t.string "url" t.string "ipordns" t.text "description" t.datetime "created_at" t.datetime "updated_at" t.s

我有一个类,其中我没有从GETAPI调用中获取整个模式

My schema.rb:

create_table "jumpsquares", force: true do |t|
 t.string   "name"
 t.integer  "apptype"
 t.string   "url"
 t.string   "ipordns"
 t.text     "description"
 t.datetime "created_at"
 t.datetime "updated_at"
 t.string   "tag"
 t.string   "jscreator"
 t.string   "remotetype"
end
在执行GET API调用时,name、apptype、url、ipords、description、created_at和updated_at的属性都可用,但是不会检索tag、jscreator和remotetype的属性。这些特定属性是为了添加额外列而进行的3次不同的数据库迁移的结果

我的remotetype迁移:

class AddRemoteAccessColumnToJumpSquares < ActiveRecord::Migration
 def change
  add_column :jumpsquares, :remotetype, :string
 end
end
型号:

class Jumpsquare < ActiveRecord::Base
 has_many :apptypes
 has_and_belongs_to_many  :tags

 def self.search(search)
  if search
   where('name ILIKE ? OR ipordns ILIKE ? OR url ILIKE ?', "%#{search}%", "%#{search}%", "%#{search}%")
  else
  all
  end
 end       
end

我假设您看到的json是由什么生成的?这只是基本的rails脚手架。此时不使用gem。您可以发布您的模型代码以及处理GET请求的代码吗?修改原始post以添加模型代码和GET请求
class Jumpsquare < ActiveRecord::Base
 has_many :apptypes
 has_and_belongs_to_many  :tags

 def self.search(search)
  if search
   where('name ILIKE ? OR ipordns ILIKE ? OR url ILIKE ?', "%#{search}%", "%#{search}%", "%#{search}%")
  else
  all
  end
 end       
end
resource = RestClient::Resource.new( 'http://localhost:3000/jumpsquares' )
response = resource.get({'Accept' => 'application/json', 'Content-Type' => 'application/json'})
parsed_response = JSON.parse(response.body)
puts parsed_response

parsed_response.each do |jumpsquare|
 jsresource = RestClient::Resource.new( jumpsquare["url"] )
 jsresponse = jsresource.get({'Accept' => 'application/json', 'Content-Type' => 'application/json'})
 jsparsed_response = JSON.parse(jsresponse.body)
 puts jsparsed_response
end