From d13bd950458aaa864e014a008f4af56a55d826b4 Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Fri, 16 May 2014 19:04:02 +0800 Subject: [PATCH] . --- rails-tricks.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ time.md | 5 +++++ 2 files changed, 53 insertions(+) diff --git a/rails-tricks.md b/rails-tricks.md index 8cb518340..5184ef7df 100644 --- a/rails-tricks.md +++ b/rails-tricks.md @@ -11,3 +11,51 @@ in config/environments/development.rb: # Don't break apart config.assets.debug = false + +Partial locals + + <%= render 'article', full: true %> + <%= render 'article' %> + + <% if local_assigns[:full] %> + ... + <% end %> + +HTML in i18n + + en: + read_more_html: "read more..." + +Exception handling: + + # config/application.rb + config.exceptions_app = self.routes + + get '/404', to: 'errors#not_found' + get '/500', to: 'errors#server_error' + + class ErrorsController + def not_found + render status: :not_found + end + end + +Rails updating: + + rake rails:update + +Distinct pluck: + + Article.distinct.pluck('author') + +Relation#merge + + scope :with_drafts, -> { + uniq.joins(:articles).merge(Article.draft) + } + +Order + + scope :recent, -> { order created_at: :desc } + + diff --git a/time.md b/time.md index 0c8379ccf..d81aef780 100644 --- a/time.md +++ b/time.md @@ -71,3 +71,8 @@ layout: default a, A - AM/PM Misc DDD, DDDD - Day of year + +Examples: + + YYYY-MM-DD - 2014-01-01 + dddd, MMMM Do YYYY - Friday, May 16th 2014