Tuesday, October 20, 2009

Ralis 2.2 with mysql Resolved errors

When you work in Rails 2.2 , with mysql you may get following error after installing mysql driver and trying to run the project.

!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install
the mysql gem and try again: gem install mysql.
rake aborted!
126: The specified module could not be found. - C:/Ruby/lib/ruby/gems/1.8/gems
/mysql-2.8.1-x86-mswin32/lib/1.8/mysql_api.so

The problem for above error is, MySQL 5.1 client library doesn't play well with Rails.

Solution is

  • copy the downloaded file to C:\Ruby\bin (or wherever you installed Ruby)

  • restart MySQL server

Wednesday, October 14, 2009

Rails Set the Index Page

Follow the steps given bellow
1. Delete public/index.html
2. Add 'map.root :controller => ""' to routes.rb
3. and then of course create the controller with the action index.

Java Script Validations in RESTful Ruby on Rails Form

We can validate ruby on rails form using java script.It is show in bellow example

java script function

function validate()
{
//validation code
if (valid)
return true
else
return false
}

ruby on rails form

<% form_for(@patient_details,:html=>{:onsubmit=>"return validate();"}) do |f| %>
<%= f.error_messages %>
#form

<%end%>

Switch statement in ruby on rails

In other languages switch case statement use for avoiding many if else conditions. In ruby also use these type of tack-tick for avoid many if else conditions.

try this code

exapmle 1
case name
when "banusha"
#some_code
when "kamal"
#some_code
else
#...
end

example 2

case number
when 1
puts "number is equal to 1"
when 2..9
puts "number is between 2 and 9"
when 10
puts "number is equal to 10"
end

example 3

case number
when 1 then puts "number is equal to 1"
when 2..9 then puts "number is between 2 and 9"
when 10 then puts "number is equal to 10"
end
example 4

case number
when 1 ; puts "number is equal to 1"
when 2..9 ; puts "number is between 2 and 9"
when 10 ; puts "number is equal to 10"
end


Ruby on Rails -try catch fainally block

Ruby On Rails in more human readable language than other languages. So ruby use try catch finally block also human readable form as follows.begin,rescue,ensure same as try catch finally

begin
somecode()
rescue

puts "error"
ensure

all_ways_execute_code
end

Acts_as_Authenticated Plugin in Rails

In ruby on rails environment by using this plugin we can built a login system with all most all the function, with in few minitues. Follow the steps in bellow

1.Install the plugin: script/plugin install http://svn.techno-weenie.net/projects/plugins/acts_as_authenticated
2. Generate the user and account models: script/generate authenticated user account
3. Rake the DB to add the users table: rake db:migrate
4. Finally, add this line to application.rb controller so you can use the gem: include AuthenticatedSystem

Type Url -http://localhost:3000/account/signup
Then you can see the sign up page
Type- http://localhost:3000/account/login
then you can see tha login page

To protect pages so they require login, simply add this line to the beginning of your controller class:

before_filter :login_required

If you want to exclude certain views from requiring authentication, just add the list of exceptions:

before_filter :login_required, :except => [:show]

def show
# view stuff ...
end

Monday, September 28, 2009

Ruby on Rails Vs Java

Java is very popular programming language in the world but ruby on rails is relatively new and young programming language. To compare two programming languages normally SW Engineers consider about language performance, security, Development speed, Maintainability,Scaling and Development tools
By comparing with Rails and Java, Rails Development speed and Maintainability little bit higher than Java. Reason for that is ruby on rails is less configuration and also it practice agile development, further more lot of plugins are available for ruby on rails development.But consider about scalability rails is in far behind to java. Java supports multi- threading but ruby not that much.Clustering also good in Java but not that much in rails. Ruby on Rails is easy to learn and code is more human readable but Java is hard to learn and not that much human readable.




Ruby on Rails Vs PHP

Ruby on Rails is a relatively new and young programming language. But Php is little bit older than ruby on rails and many people have experience with it. According to my view both languages are easy to learn.
Before select a language for a project SW Engineers normally consider about language performance, security, Development speed,Maintainability,Scaling and Development tools
By comparing rails and php , ruby development speed and maintainability little bit higher than php. Reason for that is ruby on rails is less configuration and also it practice agile development, further more lot of plugins are available for ruby on rails development.According to my view security is same in both rails and php.Because both lanuages are support SSL implementation.And Ruby has less code than php.And also ruby codes are more human readable than the php code..

What is the Best????????








Google Map With Ruby On Rails Application

In this post i like to describe integration of the google map with the ruby on rails application. Most of the time for our projects ,we have to use google map for find a place,mark some important locations ect..

Mark a location in a google map

Google map API is totally javascript. So convert to java script variable in to Ruby variable little bit difficult. So i use a trick for make life easy. Trick was i placed a hidden fields for both' lag' and 'lat'.And get those variables as 'params' when submit the form

Find Mark Locations

It is easy.You want to get lng and lat values from your database and Simlpy can disply by Using following code

For more informtaion- http://code.google.com/apis/maps/

Ruby on Rails Vs .NET








Sending and Receiving SMS messages via a GSM modem or Mobile phone

Most of the time, we need to send and receive SMS messages in our University/School Projects. I Used Java library called SMSLib for my above requirement. SMSlib is a Java library for sending and receiving SMS messages via a GSM modem or mobile phone. It also supports some bulk SMS operators, by implementing their HTTP interfaces.

For more Information - http://code.google.com/p/smslib/

Friday, September 18, 2009

Date Time Formats in Ruby

strftime( string ) method of the 'Date' class can use for that purpose..

eg - t = Time.now
t.strftime("%m/%d/%Y") #=> "19/09/2009"
t.strftime("%I:%M%p") #=> " 12:22PM"

Format Strings

%a - The abbreviated weekday name (``Sun'')
%A - The full weekday name (``Sunday'')
%b - The abbreviated month name (``Jan'')
%B - The full month name (``January'')
%c - The preferred local date and time representation
%d - Day of the month (01..31)
%H - Hour of the day, 24-hour clock (00..23)
%I - Hour of the day, 12-hour clock (01..12)
%j - Day of the year (001..366)
%m - Month of the year (01..12)
%M - Minute of the hour (00..59)
%p - Meridian indicator (``AM'' or ``PM'')
%S - Second of the minute (00..60)
%U - Week number of the current year,
starting with the first Sunday as the first
day of the first week (00..53)
%W - Week number of the current year,
starting with the first Monday as the first
day of the first week (00..53)
%w - Day of the week (Sunday is 0, 0..6)
%x - Preferred representation for the date alone, no time
%X - Preferred representation for the time alone, no date
%y - Year without a century (00..99)
%Y - Year with century
%Z - Time zone name
%% - Literal ``%'' character

Fixed Length Random numbers Ruby On Rails

Generating Random numbers in Ruby On Rails is very easy even without gems.

If u want 6 Digit random number try bellow code.
rand(999999).to_s.center(6, rand(9).to_s)

If you want 5 digit try bellow
rand(99999).to_s.center(5, rand(9).to_s)

Like this we can generate any number of digits random number..

Thursday, May 28, 2009

Setup Ruby on Rails in the Windows platform

1.First Download the Ruby setup. You can get the Ruby setup by following this link http://rubyonrails.org/download

2.By using this setup you can install ruby on your windows machine...After install ruby you can check the ruby version by typing ‘ruby –v’ command in the dos prompt.

3.Then we have to install rails frame work. If you have online connection type ‘gem install rails’ in the windows prompt...Then we can easily install the rails frame work.

4.After install rails we can check the version of the rails by typing ‘rails –v’ on the command prompt.

5.Then we have to decide the database we going to use in this application. In this example I use postgreSQL database. Download the postgreSQL windows setup
(http://www.postgresql.org/download/windows), and install it.

6.Then we have to install Ruby-Postgres gem using the command ‘gem install ruby-postgres’ in the command prompt.

7.Now your basic installation of the Ruby on Rails in the windows platform has completed.

Thursday, May 21, 2009

Advantages of Ruby on Rails

Advantage of using Ruby on Rails is that it proves very useful while developing database driven websites and applications. It supports databases like Mysql, Postgresql, and Oracle etc. and also provides developers with detailed error logs so as to enable them to debug applications. Users have the facility to develop search engine friendly URL’s for dynamic websites (which have query strings and delimiters like question mark) using the RoR framework. Its MVC (model view architecture) enables data and logic to be separated from presentation. The wide range of libraries provided to developers helps in simplifying the coding of common programming languages tasks such as form validations, sessions management etc. The active record feature in rails simplifies data handling in databases as it automatically maps tables to classes and rows to objects. All these features have made Ruby on Rails a popular framework amongst the open source developers’ community as it helps in rapid application development.

Ruby On Rails


Ruby on Rails, RoR is an open source web development framework, which has taken the web application space by storm. Ruby has been popularly known as object oriented general-purpose programming and scripting language since 1995. Released in the year 1995, Ruby is being used in many sectors including artificial intelligence (AI) and Machine learning programs. Written in a simple syntax, Ruby is easy to create, maintain, and edit.
Rails web application development framework was written using the Ruby programming language. The benefit of using Ruby on Rails as a framework is that it allows applications to be developed faster using simple methods. Ruby as a programming language is known to be a hybrid between Perl and Smalltalk and is considered quite similar to the Perl and Python Programming languages. Applications developed using this open source technology framework. can easily run on any server, which implements CGI or FastCGI.