Friday, April 26, 2013
How to Setup Development Environment to Contribute to Rails
Use the Rails Dev Box available at : https://github.com/rails/rails-dev-box
Thursday, April 25, 2013
How to store array in mysql database in a Rails project
1. The column type should be text
2. serialize the column. In the active record class : serialize :your_field
3. Book.new(:your_field => [1,2])
Tuesday, April 23, 2013
Monday, April 22, 2013
Correction to Example in Ruby Programming Language
In Ruby 2.0, I had to make changes to the given code in the book:
birthyear = 1975
generation = case birthyear
when 1946..1963 then "Baby Boomer"
when 1964..1976
"Generation X"
when 1978..2000
"Generation Y"
else nil
end
p generation
Thursday, April 18, 2013
How to use VCR, Webmock with RSpec
1. Add the gems to the Gemfile under test group:
gem "webmock"
gem "vcr"
2. bundle
3. require 'vcr' as the first line in spec_helper.rb
4. Add
VCR.configure do |c|
c.cassette_library_dir = 'spec/fixtures/cassettes'
c.hook_into :webmock
c.ignore_localhost = false
c.allow_http_connections_when_no_cassette = true
end
inside the configure block.
5. Add WebMock.allow_net_connect! in the before block in the specs.
6. Wrap your network calls using :
VCR.use_cassette do
controller code that accesses network goes here
end
Friday, April 12, 2013
Two different ways to execute a block
It is familiar that you will see yield being used when the block is anonymous and block.call being used when the block is explicit in the list of parameters for the method. Actually, you can use yield even when the block is explicitly passed to the method:
def foo(&block)
yield
block.call
end
foo { puts 'hi hey again' }
def foo(&block)
yield
block.call
end
foo { puts 'hi hey again' }
Tuesday, April 02, 2013
Setting two spaces as the default in Sublime Text 2
{ "tab_size": 2, "translate_tabs_to_spaces": true }
Save this in the Preferences -> Settings - Default file.
Installing Guest Additions on Ubuntu 12.04
1. sudo apt-get install virtualbox-guest-additions-iso
2. Boot the guest OS inside Virtualbox
3. In the virtual box menu, use Devices -> Install Guest Additions.
Reference: ubuntuforums.org
2. Boot the guest OS inside Virtualbox
3. In the virtual box menu, use Devices -> Install Guest Additions.
Reference: ubuntuforums.org
Monday, April 01, 2013
uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)
This happens when creating a new project in Rails 2.3.8 if the Ruby gems version is 1.8.24.
Solution:
Solution:
gem update --system 1.5.3
Now, rails blog will create a new project.
program rails is not installed ubuntu rvm rails 2.3.8
1. Type : gem env, look at the EXECUTABLE DIRECTORY value
2. Add the path to that directory to ~/.bashrc:
PATH="${PATH}:/home/your-user-name/.rvm/gems/ruby-1.8.7-p299/bin"
3. Open a new terminal
4. Type : rails -v
You will now see that rails command is recognized.
2. Add the path to that directory to ~/.bashrc:
PATH="${PATH}:/home/your-user-name/.rvm/gems/ruby-1.8.7-p299/bin"
3. Open a new terminal
4. Type : rails -v
You will now see that rails command is recognized.
Subscribe to:
Posts (Atom)