firstruby

Master ruby with us

json gem installation problem in Ruby on Rails 3.0 on Windows and usage of DevKit

Posted by firstruby on November 13, 2011

While installaing json gem in Ruby on Rails 3.0 or 3.1, I was getting following error,

firstruby@FIRSTRUBY /demo
$ gem install json -v=1.4.6 –platform=ruby –no-ri –no-rdoc
Fetching: json-1.4.6.gem (100%)
ERROR: Error installing json:
The ‘json’ native gem requires installed build tools.

Please update your PATH to include build tools or download the DevKit
from ‘http://rubyinstaller.org/downloads’ and follow the instructions
at ‘http://github.com/oneclick/rubyinstaller/wiki/Development-Kit’

firstruby@FIRSTRUBY /demo

To fix this problem, need to install Development Kit (DevKit – Its a toolkit that makes it easy to build and use native C/C++ extensions for Ruby on Windows) as follows,

1) Download DevKit file from http://rubyinstaller.org/downloads (DevKit-tdm-32-4.5.2-20110712-1620-sfx.exe)
2) Extract DevKit to path C:\Ruby192\DevKit
3) Goto DevKit installation directory,

cd C:\Ruby192\DevKit

4) Run following command,

ruby dk.rb init

It will generate the config.yml file. This config file should include installed Ruby path, like “C:\Ruby192”
5) Run following command,

ruby dk.rb review

It is useful to review the list of Rubies to be enhanced to use the DevKit and verify the changes you made to it are correct.
6) Run following command,

ruby dk.rb install

It is useful to enhance your installed Rubies and makes it easy to build and use native C/C++ extensions such as json.

Reference : https://github.com/oneclick/rubyinstaller/wiki/Development-Kit

Posted in Useful Links | Tagged: , , , , | 25 Comments »

How to pass command line argument to Rake task

Posted by firstruby on October 2, 2011

Following is the way to pass command line argument to Rake task,

rake app:test argument_name=’Hello World’

And read command line argument in following rake task,

namespace :app do
desc ‘test’
task :test => :environment do |t|
puts ENV[‘argument_name’]
end
end

Posted in Useful Links | Tagged: | Leave a Comment »

Protected: Ruby on Rails 3.1.x application Deployment on Heroku

Posted by firstruby on September 1, 2011

This content is password protected. To view it please enter your password below:

Posted in Useful Links | Tagged: , , , | Enter your password to view comments.

Mysql::Error: query: not connected while rake db:migrate

Posted by firstruby on August 25, 2011

With Ruby 1.9.2 and Rails 3.0.10,
If you are facing following problem while doing “rake db:migrate”,

Mysql::Error: query: not connected: SHOW TABLES

then you may need to download ‘libmySQL’ from http://instantrails.rubyforge.org/svn/trunk/InstantRails-win/InstantRails/mysql/bin/libmySQL.dll and paste that in C:\Ruby192\bin folder.

Posted in Useful Links | Tagged: , , , , | Leave a Comment »

OpenSSL::Cipher::CipherError (Illegal key size) in jRuby on Rails application

Posted by firstruby on July 17, 2011

If you got following error,

OpenSSL::Cipher::CipherError (Illegal key size)

it means you need to install ‘Java Jurisdiction policy files’. These files can be downloaded from http://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.html and copy ‘local_policy.jar’, ‘US_export_policy.jar’ and replaced at ‘C:\Program Files\Java\jdk1.6.0\jre\lib\security’.

Posted in Useful Links | Tagged: , , , , | 1 Comment »

HTTP authentication for Ruby on Rails application

Posted by firstruby on June 23, 2011

You may want to add HTTP authentication to your Ruby on Rails site, add following to your application controller file,


before_filter :authenticate

protected

def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == "test" && password == "test"
end
end

After adding these lines, application will ask for username and password.

Posted in Useful Links | Tagged: , , , | Leave a Comment »

Language fallback mechanism in Ruby on Rails

Posted by firstruby on May 29, 2011

Language fallback mechanism in Ruby on Rails is very useful. It is useful in 2 ways,

1) File missing : If particular locale file say German locale ‘de’ is set from browser, then Rails application will look for de.yml file in /config/locales folder, and if de.yml is missing, then by default language fallback mechanism will load en.yml file as default.

2) Entry missing: If German locale ‘de’ is set from browser, then Rails application will look for de.yml file in /config/locales folder. In case, particular entry is missing in de.yml file, then conversion for the same language will be loaded from en.yml file.

To achieve this, just need to install latest I18n gem and need to create file /config/initializers/i18n.rb file with following,

I18n.backend.class.send(:include, I18n::Backend::Fallbacks)

Reference URL : http://stackoverflow.com/questions/2324398/fall-back-to-default-language-if-translation-missing

Posted in Useful Links | Tagged: , , , | Leave a Comment »

Protected: Ruby on Rails 3.0.x application Deployment on Heroku

Posted by firstruby on March 17, 2011

This content is password protected. To view it please enter your password below:

Posted in Useful Links | Tagged: , , , | Enter your password to view comments.

Regular Expression to skip alphabets, accepts numbers and few characters

Posted by firstruby on February 20, 2011

Following is the Regular expression which accepts numbers, plus (+), miuns (-) symols and skips alphabets,

RegEx:   /\A[+\-0-9]+\z/

This RegEx can be useful for Phone number validation.

Posted in Useful Links | Tagged: , | Leave a Comment »

Call Helper method from ActionMailer views in Ruby on Rails application

Posted by firstruby on February 2, 2011

If you want to call helper method from ActionMailer view in Ruby on Rails (RoR) application, you need to include helper (module) in Mailer file as,

If Helper module name is “UserHelper”, then need to write following in Mailer file,

add_template_helper(UserHelper)

After this, you will be able to access all the methods written in UserHelper in ActionMailer views.

Hope this is helpful.

Posted in Useful Links | Tagged: , , , | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.