README.md in tuning-0.3.3 vs README.md in tuning-1.0.0

- old
+ new

@@ -19,47 +19,110 @@ $ bundle ``` ## Controllers -Use error method to respond with status 500 and show 500.html (if format it's html): +New callbacks before, after, around render are available: ```ruby -error -``` +class ProductsController < ApplicationController -Use not_found to respond with status 404 and show 404.html (if format it's html): -```ruby -not_found + before_action :set_product + before_render :prepare_product + + def edit + end + + private + + def set_product + @product = Product.find(params[:id]) + end + + def prepare_product + @product.build_picture + end + +end ``` -Use unauthorized to respond with status 401 and show 422.html (if format it's html): -```ruby -unauthorized +## Mailers + +Text email templates will normalize spaces and new lines like html: +```erb +<% if @order.confirmed? %> + Your order has been confirmed. + + Will be delivered right the way. +<% end %> ``` -Use forbidden to respond with status 403 and show 422.html (if format it's html): -```ruby -forbidden +Will produce: ``` +Your order has been confirmed. -Use unprocessable_entity to respond with status 422 and show 422.html (if format it's html): -```ruby -unprocessable_entity +Will be delivered right the way. ``` ## Views -Use content_tag_if if you want wrap content into some tag if certain condition it's true: +New content_tag_if method to wrap content into some tag if certain condition it's true: ```erb <%= content_tag_if request.path == home_path, :h1 do %> <%= link_to 'Home', home_path, id: 'logo' %> <% end %> ``` -Use active_trail? if you want to check if some path is on active trail: +New active_trail? method to check if some path is on active trail: ```erb <li class="<%= 'active' if active_trail? some_path %>"></li> ``` + +New extending method to extend layouts: +```erb +<%= extending :application do %> + <p>content</p> +<% end %> +``` + +## Records + +Empty strings will be nilify in the database to avoid sql errors or complex queries: +```ruby +shop = Shop.new(name: '') +shop.save +shop.name # Will be nil +``` + +New method validate is available to allow a more expressive syntax: +```ruby +record.validate # Same as valid? +``` + +## Validations + +Complexity validator to avoid weak passwords: +```ruby +class User < ActiveRecord::Base + validates_complexity_of :password +end +``` + +Count validator to express count messages instead of length messages: +```ruby +class Product < ActiveRecord::Base + validates_count_of :pictures, minimum: 1, maximum: 4 # Or in/within: 1..4 +end +``` + +Time validator to validate Date/Time values: +```ruby +class Schedule < ActiveRecord::Base + validates_time_of :opens_at + validates_time_of :closes_at, after: :opens_at # Or before, after_or_equal_to or before_or_equal_to +end +``` + +NOTE: Take a look at lib/tuning/locales to know the i18n keys. ## Credits This gem is maintained and funded by [mmontossi](https://github.com/mmontossi).