5 ms·
Ask HN: What are you favorite quick Rails tricks/tips?
Don't list too many, preferably ones that can be concisely explained in a line or 2 (max).
For instance, I just discovered that an easy way to access helper methods in your console is to just use `helper.<helper_method>`.
E.g. To read a BigDecimal attribute and convert to currency in your console (without having to include any Helper classes) just do:
`helper.number_to_currency(some_price, precision: 2)`[1]
What are some quick ones you have encountered that you now use regularly?
*[1] - Credit goes to Nick @ 37Signals http://37signals.com/svn/posts/3176-three-quick-rails-console-tips for this tip.
- rman666 14y agoUse Sinatra (http://sinatrarb.com http://sinatrarb.com)
- dmak 14y ago= @user.name || "Not available" If user's name exists, print it else print not available.
- jyu 13y agoIf 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
- deleted 13y ago[deleted]
- MattBearman 14y agoThis 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 14y agoHrmm....Better_errors gives you something similar after a 404 or some other error - along with an IRB in the browser.
- jyu 14y agoNot really a trick, but pry-rails has helped me in a lot of sticky situations.