Rails: Disable options of a select field
Simply give the select
helper an option :disabled
, passing either a single value or an array. You need to specify the option's value
, not its text.
= form.select :country, Address.countries_for_select, :include_blank => true, :disabled => ['disabled-value1', 'disabled-value-2']
Also see Cucumber: Check if a select field contains a disabled option on how to test this.
YAML: Keys like "yes" or "no" evaluate to true and false
If you parse this Yaml ...
yes: 'Totally'
no: 'Nope'
... you get this Ruby hash:
{ true: 'Totally',
false: 'Nope' }
In order to use the strings 'yes' and 'no' as keys, you need to wrap them with quotes:
'yes': 'Totally'
'no': 'Nope'
There's actually a long list of reserved words with this behavior:
y|Y|yes|Yes|YES|n|N|no|No|NO
|true|True|TRUE|false|False|FALSE
|on|On|ON|off|Off|OFF
I'm sorry.
dusen and edge_rider gems no longer depend on Rails
dusen 0.4.8 and edge_rider 0.2.3 no longer depend on Rails (they still depend on ActiveRecord). That means you can use them e.g. with Sinatra.
Couldn't create database for ...
When you run rake db:create
and get this error message
Couldn't create database for {"encoding"=>"utf8", "username"=>"root", "adapter"=>"mysql", "database"=>"project_development", "password"=>"topsecret"}, charset: utf8, collation: utf8_unicode_ci (if you set the charset manually, make sure you have a matching collation)
make sure the user you have specified (root/topsecret) in your database.yml
has access to MySQL. You can check this by running mysql -uroot -p
.
Responding to the OPTIONS HTTP method request in Rails: Getting around the Same Origin Policy
Code example for implementing Cross-Origin Resource Sharing (CORS) in Rails.
Rails 3.1: Release candidate
Asset pipeline, HTTP streaming, jQuery as default framework, auto-reversable migrations, identity map for ActiveRecord.
Ruby 1.8.x support will be dropped with or after Rails 4.
Problems with Rails 3 Remote Links and Forms Using jQuery .live() in IE
There is a problem with AJAX response handling for Rails 3 remote links and forms in Internet Explorer. This problem affects applications still using jQuery 1.4.2.
rhulse's rails-css-views at master - GitHub
This gem is designed to provide CSS views to Rails, and a process to concatenate and minify these files to one file for production.
Automatic Flushing: The Rails 3.1 Plan « Katz Got Your Tongue?
This post explains, in some detail, how we will implement a nice performance boost for Rails developers. Understanding the details might help gain the full benefits of the optimization, but you will gain some benefits even if you have no idea how it works.
The Rails Internationalization (I18n) API
This guide will walk you through the I18n API and contains a tutorial how to internationalize a Rails application from the start.
Translations available in rails
YAML List of all translations currently available in Rails
Rails 2.3 Nested Object Forms: I’m not Crazy about Them « SmartLogic Solutions Blog
I just finished reviewing Rails 2.3 Nested Object Forms. While a very nice and “magical” feature, I’ve got to admit that I’m really not that crazy about how it works.
Rails plugin testing guide
This article is an introduction to testing Rails plugins.
The Bark Blog » Testing Rails Model Plugins
Unfortunately, by default plugin tests are pretty bland. They use the plain unit test suite supplied by Ruby, and not any of the extended Rails test framework. This will leave our plugin’s test classes with no access to fixtures, database.yml configuration, or any of those nice class auto-loading features.
svenfuchs's rails-i18n at master - GitHub
Central point to collect locale data for use in Ruby on Rails.
paperplanes. run_later Gets Some Rails 2.3 Middleware Love
In earlier version I needed to do an awkward thing that only affected development mode, where Rails unloads all classes after each request. run_later runs code in a separate thread, and depending on how long that code runs the classes would be unloaded when they're still accessed from the worker.
Rails Envy: 6 Reasons to use Webbynode
Webbynode is a very affordable VPS host (256 RAM for $15) which has great support for Rails applications.
Codaset // joelmoss / Rails Concerns
Concerns is a simple Rails plugin that provides you with a simple way to organise your Controllers, Models and Mailers, and split them into smaller chunks of logic. It is especially useful when you have lengthly models, and you get fed with having to scroll through several hundred lines of code.
has_many :bugs, :through => :rails: Active Record Query Interface 3.0
So here’s an overview of how things are going to work in Rails 3.
Rails 2: Calling instance_eval on a scope will trigger a database query
In Rails 2, when calling instance_eval
or instance_exec
on a scope, the scope will fetch its records from the database.
This has been fixed in Rails 3+.
Disable Rails XSS protection in ActionMailer views
This might eventually be fixed by Rails itself.\
Right now this is the way to have the rails_xss plugin not escape the body of ActionMailer mails.
Put this into config/initializers/mailers_without_rails_xss.rb
:
Get compiled code of a view template in Rails 4.2
If you want to inspect the compiled code of your erb (or haml) templates, you can run the following code in your view or your controller:
template = lookup_context.find_template(action_name, lookup_context.prefixes)
template.handler.call(template.refresh(self))
The output will be something like
@output_buffer = output_buffer || ActionView::OutputBuffer.new;@output_buffer.safe_append='My template
'.freeze;@output_buffer.to_s