0

I have a script(script/seed.rb), working with SCV file. I want to use "update_my_controller_name_path" helper instead of "localhost:3000/update". A simple helpers, such as "root_path" and etc. didn't work. The question is how can I simply get some controller and action, which I want to request instead of "localhost:3000/update" ? Here is my code(script/seed.rb):

  require 'rest_client'
require 'csv'

  CSV.foreach('data/seed_data.csv', headers: true)  do |row|
     RestClient.get 'localhost:3000/update', :params => {:temp => row['temp'], :hum => row['hum']} 
  end
ilyabyar
  • 5
  • 4

1 Answers1

0

Add require './config/environment to the top of your script. This will boot up your rails app, build routes and make the route helpers available for you to use in your script via the url_helpers module:

require './config/environment'
Paths = Rails.application.routes.url_helpers

Paths.root_path
Paths.update_my_controller_name_path

Note: this will slow down your script by a few seconds.

2nd Note: You may need to make it require '../config/environment' since your seeds script is not in the rails root.

DiegoSalazar
  • 13,361
  • 2
  • 38
  • 55