Difference between revisions of "Ruby on Rails"

From Hawk Wiki
Jump to: navigation, search
Line 27: Line 27:
 
"  ".empty? == false
 
"  ".empty? == false
 
</pre>
 
</pre>
 +
<h3>How to skip active record in rails 3</h3>
 +
1. Create new rails project with
 +
<pre>
 +
rails new myApp --skip-activerecord
 +
</pre>
 +
2.
 +
 +
In application.rb, remove the require 'rails/all' line and instead add these lines:
 +
<pre>
 +
require "action_controller/railtie"
 +
require "action_mailer/railtie"
 +
require "active_resource/railtie"
 +
require "rails/test_unit/railtie"
 +
require "sprockets/railtie"
 +
</pre>
 +
Also see Remove ActiveRecord in Rails 3 and look into the Active Model railscast
 +
 +
Rails 3.2.x:
 +
 +
You'll also need to remove/comment out this line in application.rb
 +
<pre>
 +
config.active_record.whitelist_attributes = true
 +
</pre>
 +
And remove/comment these two lines from development.rb
 +
<pre>
 +
config.active_record.mass_assignment_sanitizer = :strict
 +
config.active_record.auto_explain_threshold_in_seconds = 0.5
 +
</pre>
 +
Rails 2.x:
 +
 +
In config/environment.rb add (or uncomment) the line
 +
<pre>
 +
config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
 +
</pre>
 +
This will cause Rails not to use those frameworks. (Note the nearly-invisible -= !)

Revision as of 20:20, 31 August 2014

Tutorials

Beginner's tutorial
http://allaboutruby.wordpress.com/2006/01/09/installing-rails-on-windows-step-by-step-tutorial/
Ruby in 20 minutes
http://www.ruby-lang.org/en/documentation/quickstart/

nil?, empty? and blank?

.nil? can be used on any object and is true if the object is nil.

.empty? can be used on strings, arrays and hashes and returns true if:

String length == 0
Array length == 0
Hash length == 0

Running .empty? on something that is nil will throw a NoMethodError.

.blank? will operate on any object
nil.blank? == true
false.blank? == true
[].blank? == true
{}.blank? == true
"".blank? == true
5.blank? == false
"  ".blank? == true
"  ".empty? == false

How to skip active record in rails 3

1. Create new rails project with

rails new myApp --skip-activerecord

2.

In application.rb, remove the require 'rails/all' line and instead add these lines:

require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"
require "sprockets/railtie"

Also see Remove ActiveRecord in Rails 3 and look into the Active Model railscast

Rails 3.2.x:

You'll also need to remove/comment out this line in application.rb

config.active_record.whitelist_attributes = true

And remove/comment these two lines from development.rb

config.active_record.mass_assignment_sanitizer = :strict
config.active_record.auto_explain_threshold_in_seconds = 0.5

Rails 2.x:

In config/environment.rb add (or uncomment) the line

config.frameworks -= [ :active_record, :active_resource, :action_mailer ]

This will cause Rails not to use those frameworks. (Note the nearly-invisible -= !)