-1

I want to print a JSON object in the browser's console, I searched a lot but I din't find any appropriate result.

Here is my ruby controller:

class ScheduleTime < ApplicationController

available_schedule = ScheduleTimeSlot.where(:doctor_id => params[:dr_id],:date=>params[:for_date].to_date,:status=>"vacant",:archive=>false).reorder(:start_time)

render :json =>{:available_schedules=>available_schedules}

//here I need a syntax that print the available_schedule on browser console (if possible) or ruby console, so I can debug it properly.

end

Thanks In Advance

Vishal Nagda
  • 1,165
  • 15
  • 20
  • The reason you can't find any existing answers is because this doesn't really make sense. Can you explain why you think this is necessary? – user229044 Aug 15 '16 at 11:51

1 Answers1

1

You can't access the browser's console directly from your controller, and if you're trying to do so, it's probably because you're doing something wrong. Your controller (like all Ruby code in your application) runs on the server, and whatever logging you do will be output in the server's logs, not on the client.

If you want to write to the browser's console, you need to send JavaScript to the client which does that. That means outputting script from your controller to the browser. You will have to wrap your JSON output in <script>console.log(...)</script> and change your output format to JavaScript, not JSON.

user229044
  • 232,980
  • 40
  • 330
  • 338
  • 1
    Comments are not for extended discussion; this conversation has been [moved to chat](http://chat.stackoverflow.com/rooms/120990/discussion-on-answer-by-meagar-how-to-print-json-object-in-browser-console-usin). – user229044 Aug 15 '16 at 18:25