I'm thinking of implementing Ruby on Rails to run web APIs regularly, process data, and insert data into DB.
The model cannot be called due to an unknown cause error listed below.
lib/tasks/repository.rake
require'net/http'
require 'uri'
namespace —repository do
desc "get repositories list and delete old repositories list at 11:00 every day"
task —get_repositions do
save_repositors
delete_repositors
end
def save_repositors
languages.each do | language |
uri=
URI.parse("https://api.github.com/search/repositories?q=language: #{language}&sort=stars&order=desc")
https=Net::HTTP.new(uri.host,uri.port)
https.use_ssl=true
response = https.start {
https.get(uri.request_uri)
}
if response.code == '200'
results=ActiveSupport::JSON.decode response.body
results["items"].each do | repository |
Repository.create(name:repository["name"], language:repository["language"],
url: repository ["html_url"], scores: repository ["score"], issues: repository ["issues")
end
end
end
end
def delete_repository
puts "Hello World"
end
deflanguages
["Javascript", "Ruby", "Python", "Java", "Go"]
end
end
app/models/repository.rb
class Repository <ApplicationRecord
end
Error Description:
rake aborted!
NameError:uninitialized constant repository
If you do not have enough information, please leave a comment.
ruby-on-rails ruby
task get_repositions::environment do
hogehoge
end
As shown in , specifying environment as a dependent task seems to solve this problem.
585 PHP ssh2_scp_send fails to send files as intended
620 GDB gets version error when attempting to debug with the Presense SDK (IDE)
630 Uncaught (inpromise) Error on Electron: An object could not be cloned
579 Understanding How to Configure Google API Key
575 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.