0

I have a admin page on my site which allows me to load seeds by clicking a link.

it just calls:

Rails.application.load_seed

Problem is, there is no feedback that this is happening - I would like to see the seed output somehow on the page (the same as if ran in the command line).

Is there a way to do this when the link is clicked?

user3437721
  • 2,227
  • 4
  • 31
  • 61

2 Answers2

0

If you care about the page reloading, you could use jquery to do an ajax post request to a route, run the script (it doesn't need to be in the seed file--you could run it in the controller action you create) you're running to add data, and then in your success callback append the results.

toddmetheny
  • 4,405
  • 1
  • 22
  • 39
  • does this mean the output would continuously be displayed on the screen, the same as in the console? I would like user to see it as it happens.. – user3437721 Mar 07 '16 at 21:45
  • The user could see it happen. If you want it to be really fast, like a stack trace...you might want to break it up into multiple ajax requests, depending on how much data we're talking about. – toddmetheny Mar 07 '16 at 22:05
0

If by 'output' you mean messages printed to standard output (e.g. using puts in the seeds file), you might grab the output in the controller using the code from this SO answer):

# controller:
@output = with_captured_stdout { Rails.application.load_seed }

But this will only display after the load finishes, you won't get any info during the process. If you require that, I think you'd need some streaming techniques.

Community
  • 1
  • 1
Matouš Borák
  • 15,606
  • 1
  • 42
  • 53