Difference between revisions of "Ruby on Rails"

From Hawk Wiki
Jump to: navigation, search
 
Line 29: Line 29:
 
<h3>How to skip active record in rails 3</h3>
 
<h3>How to skip active record in rails 3</h3>
 
1. Create new rails project with  
 
1. Create new rails project with  
<pre>
+
<pre class="brush:ruby">
 
rails new myApp --skip-activerecord
 
rails new myApp --skip-activerecord
 
</pre>
 
</pre>
Line 35: Line 35:
  
 
In application.rb, remove the require 'rails/all' line and instead add these lines:
 
In application.rb, remove the require 'rails/all' line and instead add these lines:
<pre>
+
<pre class="brush:ruby">
 
require "action_controller/railtie"
 
require "action_controller/railtie"
 
require "action_mailer/railtie"
 
require "action_mailer/railtie"
Line 47: Line 47:
  
 
You'll also need to remove/comment out this line in application.rb
 
You'll also need to remove/comment out this line in application.rb
<pre>
+
<pre class="brush:ruby">
 
config.active_record.whitelist_attributes = true
 
config.active_record.whitelist_attributes = true
 
</pre>
 
</pre>
 
And remove/comment these two lines from development.rb
 
And remove/comment these two lines from development.rb
<pre>
+
<pre class="brush:ruby">
 
config.active_record.mass_assignment_sanitizer = :strict
 
config.active_record.mass_assignment_sanitizer = :strict
 
config.active_record.auto_explain_threshold_in_seconds = 0.5
 
config.active_record.auto_explain_threshold_in_seconds = 0.5
Line 58: Line 58:
  
 
In config/environment.rb add (or uncomment) the line
 
In config/environment.rb add (or uncomment) the line
<pre>
+
<pre class="brush:ruby">
 
config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
 
config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
 
</pre>
 
</pre>
 
This will cause Rails not to use those frameworks. (Note the nearly-invisible -= !)
 
This will cause Rails not to use those frameworks. (Note the nearly-invisible -= !)

Latest revision as of 17:20, 19 February 2015

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 -= !)