I will suggest the following books to learn ruby on rails
One should first learn ruby since rails is based on this. There are two interesting books I would recommend
Learning Ruby, Oreilly Publishers
The book talks about the syntactical details of Ruby in a simple and practical manner with lots of example
The other book is
Ruby For Rails,David Black,Manning Publication
The book explains Ruby as well as Rails. Lot of examples are given so that will help in easy understanding of the topic. The advantage of this book is that its a complete deal it talks about Ruby, Rails and gives an example Rails application.
For Rails:
1. http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html
Refer to the above URl. This is like the first guide that every Rails beginner must refer to. The page explains how to install rails, How to write the hello world in rails. It also gives an example to complete the overview of Rails
2. Agile Web Development with Rails,second Edition:
This is the book of Rails. Written by the creator of rails (DHH) himself is the most authenticated account of the Rails framework. Usually the books written by the language creators are little tough to understand e.g. Kernighan &Richie 's C, Bjarne Stroustrup's C++, But this book is very simple to understand. The book talks about the internals of Rails framework and also develops an application. Its a must to read book
One thing I have noticed in the books that are being written these days, the authors are more inclined towards explaining the practical aspects of the language giving examples rather than just a theoretical overview.
Showing posts with label rails. Show all posts
Showing posts with label rails. Show all posts
Sunday, February 10, 2008
Saturday, February 9, 2008
Logger in rails
By default log files are created in the log directory. But if you want to control you logs then you can specify it in the config/environment.rb file
# Include your application configuration below
#Added to include the logging capability in the code
MY_LOGGER = Logger.new("c:/logging_rail.log")
MY_LOGGER.level = Logger::DEBUG
From the code use lgger as
MY_LOGGER.info("-----------------------------");
MY_LOGGER.info("INFO: Inside function");
MY_LOGGER.info("INFO: At:"+1.hour.from_now.to_s);
MY_LOGGER.debug("DEBUG:executeQueryByID--queryid:"+params[:queryid]);
# Include your application configuration below
#Added to include the logging capability in the code
MY_LOGGER = Logger.new("c:/logging_rail.log")
MY_LOGGER.level = Logger::DEBUG
From the code use lgger as
MY_LOGGER.info("-----------------------------");
MY_LOGGER.info("INFO: Inside function");
MY_LOGGER.info("INFO: At:"+1.hour.from_now.to_s);
MY_LOGGER.debug("DEBUG:executeQueryByID--queryid:"+params[:queryid]);
Sunday, February 3, 2008
require_gem error
c:/ruby/bin/rake.bat:24: undefined method `require_gem' for main:Object (NoMethodError)
I encountered this error when I installed rails version 2.0.2. I wanted to use
call rake db:migrate
when I encountered the error
"c:/ruby/bin/rake.bat:24: undefined method `require_gem' for main:Object (NoMethodError)"
I was able to remove this error by following way:
1. open the rake.bat file. This file is present in the bin folder of ruby. For me the path was c:rubybinrake.bat
2. The file will look like the following:
@echo off
if not "%~f0" == "~f0" goto WinNT
ruby -Sx "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
goto endofruby
:WinNT
"%~d0%~p0ruby" -x "%~f0" %*
goto endofruby
#!/bin/ruby
#
# This file was generated by RubyGems.
#
# The application 'rake' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = "> 0"
if ARGV.size > 0 && ARGV[0][0]==95 && ARGV[0][-1]==95
if Gem::Version.correct?(ARGV[0][1..-2])
version = ARGV[0][1..-2]
ARGV.shift
end
end
require_gem 'rake', version
load 'rake'
__END__
:endofruby
if not "%~f0" == "~f0" goto WinNT
ruby -Sx "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
goto endofruby
:WinNT
"%~d0%~p0ruby" -x "%~f0" %*
goto endofruby
#!/bin/ruby
#
# This file was generated by RubyGems.
#
# The application 'rake' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = "> 0"
if ARGV.size > 0 && ARGV[0][0]==95 && ARGV[0][-1]==95
if Gem::Version.correct?(ARGV[0][1..-2])
version = ARGV[0][1..-2]
ARGV.shift
end
end
require_gem 'rake', version
load 'rake'
__END__
:endofruby
3. You need to replace the line
require_gem 'rake'version
with gem 'rake',version
4. The file rake.bat will now look like
@echo off
if not "%~f0" == "~f0" goto WinNT
ruby -Sx "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
goto endofruby
:WinNT
"%~d0%~p0ruby" -x "%~f0" %*
goto endofruby
#!/bin/ruby
#
# This file was generated by RubyGems.
#
# The application 'rake' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = "> 0"
if ARGV.size > 0 && ARGV[0][0]==95 && ARGV[0][-1]==95
if Gem::Version.correct?(ARGV[0][1..-2])
version = ARGV[0][1..-2]
ARGV.shift
end
end
gem 'rake', version
load 'rake'
__END__
:endofruby
if not "%~f0" == "~f0" goto WinNT
ruby -Sx "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
goto endofruby
:WinNT
"%~d0%~p0ruby" -x "%~f0" %*
goto endofruby
#!/bin/ruby
#
# This file was generated by RubyGems.
#
# The application 'rake' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = "> 0"
if ARGV.size > 0 && ARGV[0][0]==95 && ARGV[0][-1]==95
if Gem::Version.correct?(ARGV[0][1..-2])
version = ARGV[0][1..-2]
ARGV.shift
end
end
gem 'rake', version
load 'rake'
__END__
:endofruby
Hope that this should solve your problem
ActiveRecord::StatementInvalid in GreetingController#index
Mysql::Error: Unknown system variable 'NAMES': SET NAMES 'utf8'
This error occurs if you are using rails 2.0.2.
As far as I understood, in case of rails 2.0.2 when we create a new project, the default database adapter is SQLlite.
In order to use mysql, one need to explicitly tell,
rails -d mysql cookbook
Assuming that you have already created the three database tables: cookbook_development, cookbook_test, cookbook_production,
if you look at the database.yml file that is present in the config folder, you will see the the following lines
development:
adapter: mysql
encoding: utf8
database: cookbook_development
username: root
password: your_password
host: localhost
similarly for test and production.
The singular pint is the addition of the new line encoding: utf8. This is a new addition, if you were using rails version <= 2.0.1, this line is missing.
So I removed the line from development, test, production settings so that my database.yml now looks as
development:
adapter: mysql
database: cookbook_development
username: root
password: your_password
host: localhost
Now if you again run the server and try to access any function of the project from the browser the error wont occur.
Mysql::Error: Unknown system variable 'NAMES': SET NAMES 'utf8'
This error occurs if you are using rails 2.0.2.
As far as I understood, in case of rails 2.0.2 when we create a new project, the default database adapter is SQLlite.
In order to use mysql, one need to explicitly tell,
rails -d mysql cookbook
Assuming that you have already created the three database tables: cookbook_development, cookbook_test, cookbook_production,
if you look at the database.yml file that is present in the config folder, you will see the the following lines
development:
adapter: mysql
encoding: utf8
database: cookbook_development
username: root
password: your_password
host: localhost
similarly for test and production.
The singular pint is the addition of the new line encoding: utf8. This is a new addition, if you were using rails version <= 2.0.1, this line is missing.
So I removed the line from development, test, production settings so that my database.yml now looks as
development:
adapter: mysql
database: cookbook_development
username: root
password: your_password
host: localhost
Now if you again run the server and try to access any function of the project from the browser the error wont occur.
Subscribe to:
Posts (Atom)