I am tired of asking unanswered questions when using many outdated plugins / gems, and sometimes they don’t really work how I really wanted.
So my question is simple:
If I was a PHP programmer, and Rails was my first framework, what do I need to learn next so I can depend on myself when working with troublesome plugins or code snippets or tutorials?
I used to be quite good with an (rather silly now that I know MVC) e-commerce system in PHP, and normally I would just go ahead and read out the plugin’s code to find out what it does, but apparently doing so is extremely hard in Ruby on Rails, should I keep doing it, or am I going the right track? (I did learn by the way, but in very slow pace compared when I was still using PHP and that “e-commerce framework”)
This is like a generic programming question for me. If you have any troubles with some Rails plugin, you can always debug its code with a bunch of hardcore or easy methods, try to understand and fix the error. The question is, which methods should you use in particular situations.
I will give you a little example. When you are debugging your Rails application, always check either
logs/production.logorlogs/development.log(depending on mode you’re working) for errors of any kinds. Every error in Ruby/Rails is represented by a huge stack-trace that you should read from top to bottom. Like this one:Here we are! The line
ArgumentError (invalid byte sequence in UTF-8):, on the very top of this trace, always tells us the error type. It’s an argument error!After that, look at the next line:
/usr/lib/ruby/1.9.1/net/protocol.rb:294:in 'slice!'. It tells where the exception (ArgumentError) was raised in the following format:Let’s open that neglectful file and find the source around that line:
The error is on the following line:
From this point we know where the error is and only need to fix it, but this process is out of scope of my short story. I just wanted to show you how to work with errors in Rails.