$ rails g model User
belongs_to
has_one
| def convert_to_brightness_value(background_hex_color) | |
| (background_hex_color.scan(/../).map {|color| color.hex}).sum | |
| end | |
| def contrasting_text_color(background_hex_color) | |
| convert_to_brightness_value(background_hex_color) > 382.5 ? '#000' : '#fff' | |
| end |
| def is_ajax_request? | |
| if respond_to? :content_type | |
| if request.xhr? | |
| true | |
| else | |
| false | |
| end | |
| else | |
| false | |
| end |
| def tip(msg); puts; puts msg; puts "-"*100; end | |
| # | |
| # 30 Ruby 1.9 Tips, Tricks & Features: | |
| # http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/ | |
| # | |
| tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2" | |
| tip "Ruby 1.9 supports named captures in regular expressions!" |
| upstream example_backend { | |
| server unix:/var/www/example.com/shared/unicorn.sock; | |
| } | |
| server { | |
| listen 80; | |
| server_name example.com www.example.com; | |
| access_log off; | |
| error_log off; | |
| client_max_body_size 20M; |
| # ... | |
| gem 'carrierwave' | |
| gem 'fog', '~> 1.0.0' # Need to specify version, as carrierwave references older (0.9.0) which doesn't allow configuration of Rackspace UK Auth URL |
| uk: | |
| errors: | |
| messages: | |
| expired: "прострочено, створіть новий" | |
| not_found: "не знайдено" | |
| already_confirmed: "вже було підтверджено, спробуйте увійти" | |
| not_locked: "не було заблоковано" | |
| not_saved: | |
| one: "Виникла помилка, через яку неможливо зберегти зміни:" | |
| other: "Виникли помилки (загалом - %{count}), через які неможливо зберегти зміни:" |
| .ui-autocomplete { | |
| position: absolute; | |
| top: 100%; | |
| left: 0; | |
| z-index: 1000; | |
| float: left; | |
| display: none; | |
| min-width: 160px; | |
| _width: 160px; | |
| padding: 4px 0; |
This guide enables you to install (ruby-build) and use (rbenv) multiple versions of ruby, isolate project gems (gemsets and/or bundler), and automatically use appropriate combinations of rubies and gems.
# Ensure system is in ship-shape.
aptitude install git zsh libssl-dev zlib1g-dev libreadline-dev libyaml-dev
In this article, I'll walk through a basic Rails (3.2.x) setup for creating a nested resource for two models. Nested resources work well when you want to build out URL structure between two related models, and still maintain a RESTful convention. This code assumes you are running RVM to manage Ruby/Gem versions, and Git for version control.
$ mkdir family # create rvm gemset
$ echo "rvm use --create ruby-1.9.2@family" > family/.rvmrc
$ cd family # install rails
$ gem install rails # create new rails project
$ rails new . # version control