rails - hide 'source of your encoding' from terminal - ruby-on-rails

I'm new to ROR and I"m having trouble with all the text that rails spits to the terminal window. Primarily, the html from my web pages get repeated in the terminal window and I'm really just wanting to see the important stuff like sql queries and error messages. I'm wasting a lot of time scrolling throughout the terminal window trying to find what I need b/c of all the HTML that fills up the screen.
Is there an option to disable the 'source of your encoding' output?
Thanks.

You could raise your log level
The rails guide gives a good example
http://guides.rubyonrails.org/debugging_rails_applications.html#log-levels
Make sure if you are in development to change it in config/environments/development.rb
I don't know if this will really solve your problem though because I am unsure of exactly what output you are looking for. A higher log level may throw out the baby with the bathwater.

Related

Working with production.log rails

I got my production log file working. But wanted to get some suggestions onto how to work with it. I currently look at it view console and doing either
tail log/*
tail -f log/production.log
to look at it. I would like to either 1. find a better way to be able to look at the logs and perhaps with colors. 2. Can the production log file be outputted in a view where an admin user can view it?
Lastly, is there a gem that's great for emailing me when an error occurred and what the error was / how do you currently keep track of when errors happening in production?
Thanks!
For just having a nicer alternative to tail which shows the colours instead of those ESC[… codes, try less -R production.log. If you want to follow the end of the file like tail -f, use:
less -R +F production.log
There's nothing built-in for getting the log into a view as far as I know, but I suppose you could write a controller which shows (some of) the log in a view. Make sure it's secure with authentication though; you don't want to be exposing your log to the internet! Using an external service should remove this concern and it will have a load of other features. For example, I haven't tried papertrail (https://papertrailapp.com) but it's been on my to-try list for a while. It looks good and they're free for up to 100MB of logs a month. I've used airbrake (https://airbrake.io/) in the past for exception notifications but I don't think they have a free tier - just a free trial.

Rails Debugging - Exit controller prematurely

I was wondering how to exit a controller in rails and get the output up to that point.
In PHP I often used the "exit" when debugging to get only the data processed to that point. I haven't found a sollution to this in rails.
If you get a error further down in the code the view is locked from displaying <%= debug %> information.
Some would suggest console or rescue, and I know about these. But isn't there a simpler solution?
In development mode, I often just use puts or awesome_print to print something to the screen that I ran rails server from. That works pretty well for the simple cases.
For anything more complex than that, I use ruby-debug or pry to drop down into an interactive console when it hits the right point.
I have some editor shortcuts to print one of these two snippets:
require 'pry'; binding.pry
require 'ruby-debug'; debugger
Drop these in your code and you can use IRB to inspect (and manipulate) the state of your program.
I highly recommend you give pry a shot. Check it out here:
http://pryrepl.org/
http://railscasts.com/episodes/280-pry-with-rails
There is also the older ruby-debug:
http://railscasts.com/episodes/54-debugging-with-ruby-debug

how to debug web server on RoR?

I currently have a problem with a project.
it freezes before it shows the "Started GET ...." seems like it hits an infinite loop.
now i dont really have much experience with debuggers in ROR, can anyone recommend anything i can use to trace the exact origin of the problem. if i can get an error code somewhere then i might be able to fix it.
currently i am using webrick, i tried thin and it gave the exact same error.but i am willing to use anything to find the exact origin of this error.
it seems to be related to the project because all other projects works fine on my environment.
Take a look at the Rails guide on debugging.
Also try running the Rails console ("rails c"); if you can get to a command prompt at all that means that the issue is not in loading the Rails environment (e.g. a problem in application.rb) but is somewhere in the process of making a web request. If there's a failure it may give you a better error message.

ruby on rails - open flash charts

I'm trying various ways to implement pretty graphs in my app. I followed http://pullmonkey.com/projects/open_flash_chart2 steps in my app, but instead of creating test_it, I just added to my own controller. In my routes.rb, I have
resources :my_controller_name do
collection do
get 'graph_code'
end
end
also, since I don't think it could find the action my_controller_name/graph_code otherwise (I'm kind of confused as to why most tutorials leave the routes part out? Am I doing something wrong?). (I also used #graph.html_safe in my views for Rails 3)
Anyway when I go to /my_controller_name, I get the error in the flash box:
Open Flash Chart
JSON Parse Error [Syntax Error]
Error at character 0, line 1:
0: #<OpenFlashChart::OpenFlashChart:0x000001043c4b78
I don't know why this is happening. I tried creating a new app and following the guide, generating a controller named test_it. It worked (provided I corrected the routing). I can't think of how my controller is any different than test_it, except I initially generated it using a rails scaffold (so it has all the MVC parts), whereas I only generated the test_it controller. (I've also tried using/not using the json gem conflict fix, but it didn't make a difference--https://github.com/klochner/open_flash_chart/commit/00cf531387880af8c49ed5118737f0492b437f75) Thanks for any insight, I'm stumped as to why it's easy to implement on a new app but I can't add it to mine...
Thanks.
Nevermind, it seems to work if I use the old lib/base.rb instead of the json gem fix. Ah well.
Don't waste your time with Flash based charting libraries. Highcharts is definitely the way go to. It works in pretty much any browser, including those that don't support Flash. Much better performance on OS X than Flash will ever provide.

Ruby on Rails Debug Question

Hello guys I have this video tutorial on Ruby on Rails and I see that the guy has a bottom script debug, in the browser window. The problem is, I have only one part of that video tutorial (that part is free) and he says nothing about that debug. Maybe you guys can figure it out.
Here's a screenshot with it: http://i55.tinypic.com/3537drp.png
How can I achieve that? Thanks.
In the view, doing something like
<%= debug params %>
will achieve what you have shown. Using the debug helper you can basically get a yaml dump of any variable that's available to the view, it will also "prettyfy" the dump by formatting it in a <pre> block and using a different background color. From the looks of what he has, he might have added that to the bottom of a layout (might be in app/views/layouts/application.html.erb). That will give you that dump in any of your pages.
The Rails Footnotes gem is very easy to configure and includes information like:
variable assignments
params action / controller
route information
SQL statements & execution times
Check it out:
https://github.com/josevalim/rails-footnotes
Looks like he's just rendering params.to_yaml onto the page.
you should maybe consider running rails with the --debugger flag as exemplified in this guide:
http://guides.rubyonrails.org/debugging_rails_applications.html
for debugging the view you can simply <% debugger %> in your view page wherever your want to see the dataflow and load that view again and on the console you can run each line of view and see the data flow.. and make sure you have debugger gem in your gem file.

Resources