

Ask HN: What are you favorite quick Rails tricks/tips? - marcamillion

Don't list too many, preferably ones that can be concisely explained in a line or 2 (max).<p>For instance, I just discovered that an easy way to access helper methods in your console is to just use `helper.&#60;helper_method&#62;`.<p>E.g. To read a BigDecimal attribute and convert to currency in your console (without having to include any Helper classes) just do:<p>`helper.number_to_currency(some_price, precision: 2)`[1]<p>What are some quick ones you have encountered that you now use regularly?<p>*[1] - Credit goes to Nick @ 37Signals http://37signals.com/svn/posts/3176-three-quick-rails-console-tips for this tip.
======
MattBearman
This was probably well known to everyone else, but I recently discovered you
can use 'debugger' in non-test environments.

Ie: when running a non-detached webrick server, you can step though code and
launch irb in the middle of browser based request.

~~~
marcamillion
Hrmm....Better_errors gives you something similar after a 404 or some other
error - along with an IRB in the browser.

------
dmak
= @user.name || "Not available"

If user's name exists, print it else print not available.

~~~
jyu
If the value is an empty Array or Hash, you can use

@user.name.presence || "Not available"

rather than

@user.name.blank? ? "Not available" : @user.name

------
jyu
Not really a trick, but pry-rails has helped me in a lot of sticky situations.

------
rman666
Use Sinatra (<http://sinatrarb.com>)

