Monday, May 13, 2013
AbstractController::ActionNotFound:
Could not find devise mapping for path "/users/sign_in?user%5Bemail%5D=bparanj%40gmail.com&user%5Bpassword%5D=secret".
This may happen for two reasons:
1) You forgot to wrap your route inside the scope block. For example:
devise_scope :user do
get "/some/route" => "some_devise_controller"
end
2) You are testing a Devise controller bypassing the router.
If so, you can explicitly tell Devise which mapping to use:
@request.env["devise.mapping"] = Devise.mappings[:user]
Solution:
before :each do
request.env['devise.mapping'] = Devise.mappings[:user]
end
Thursday, May 02, 2013
How to select the non highlighted button in the popup window on Mac OS
Go to Preferences -> Keyboard. At the bottom, turn on "All controls" under "Full Keyboard Access". Hit space to activate the secondary button.
Wednesday, May 01, 2013
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.
Friday, March 29, 2013
How to configure Sublime Text 2 to use Ruby 2.0 using RVM
{
"env":{
"PATH":"${HOME}/.rvm/bin:${PATH}"
},
"cmd": ["rvm-auto-ruby", "$file"],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.ruby"
}
Copy this file to your rvm.sublime.build file.
For more info: Sublime Text 2 Integration With RVM and Rspec: Take Number 2
Copy this file to your rvm.sublime.build file.
For more info: Sublime Text 2 Integration With RVM and Rspec: Take Number 2
Monday, March 25, 2013
How to configure rspec to test controller macros
Include the line:
config.include OnboardingControllerMacros, :type => :controller
in spec_helper.rb
Monday, March 18, 2013
Readline was unable to be required, if you need completion or history install readline then reinstall the ruby.
This happens on Ubuntu 12 when installing Ruby 2.0 using RVM. To fix this follow the instructions below:
|
If you're using Ubuntu 12.04, DO NOT pkg install readline, with or
without --skip-autoreconf. After you've done that, either readline or
zlib will be broken no matter what combination of switches you give to
rvm install ruby-2.0.0-p0 .
To get it to work, do the apt-get install that rvm requirements tells you to do, do a rvm pkg uninstall readline and then do a simple rvm remove ruby-2.0.0-p0; rvm install ruby-2.0.0-p0Now the irb should work fine without any warnings. http://stackoverflow.com/questions/8176076/how-to-get-readline-support-in-irb-using-rvm-on-ubuntu-11-10 |
Tuesday, March 12, 2013
iPhone 5 cord stuck in USB Port
You can easily remove your iPhone 5 cable stuck in USB port by using either your shirt collar stays or a toothpick. Just stick it inside the USB port, sitting on top of the cable and pull them together.
Monday, February 25, 2013
Accessing Git Repository on Github
Problem:
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Solution:
Password Caching (Explains how to use https to access repository and cache password so you don't get annoying password prompt whenever you have to access the github repo)
1. curl -s -O \
http://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain
chmod u+x git-credential-osxkeychainsudo mv git-credential-osxkeychain `dirname \`which git\``
git config --global credential.helper osxkeychain
Subscribe to:
Posts (Atom)