I have a rake task and i'm trying to find the record in the database to be updated. Problem is when i use (params[:name]) it throws out the message undefined local variable or method `params' for main:Object. How do i make params available to the rake task? Thanks. I'm new to this and any help is appreciated.
task scrape_borisAPI: :environment do
@json = HTTParty.get("http://borisapi.heroku.com/stations.json")
@json.each do |station|
@location = Location.find(params[:name])
@location.nb_bikes = station["nb_bikes"]
@location.nb_empty_docks = station["nb_empty_docks"]
@location.update_attributes(:nb_bikes => "@location.nb_bikes", :nb_empty_docks => "@location.nb_empty_docks")
end
end
Originally the rake task looked like this and i'm trying to modify it to update records as opposed to creating new records.
task scrape_borisAPI: :environment do
@json = HTTParty.get("http://borisapi.heroku.com/stations.json")
@json.each do |station|
@location = Location.new
@location.name = station["name"]
@location.latitude = station["lat"]
@location.longitude = station["long"]
@location.nb_bikes = station["nb_bikes"]
@location.nb_empty_docks = station["nb_empty_docks"]
@location.save!
end
end