wordpress XMLRPC api integration with ruby and rails

Ruby on Rails is really OOPs based framework. I personally love this framework. I worked on this for many years. Many Ruby lovers are looking to integrate the wordpress with Ruby on Rails. I strongly suggest to integrate wordpress with ROR using XMLRPC APIs. Using following code you can easily add the wordpress into Ruby on Rails Project. Use my following steps:

wordpress XMLRPC api integration with ruby and rails

Note: There are so many XMLRPC APIs provided by wordpress. I given the some simple example here.

First setup wordpress. Login to wordpress admin and enable the XMLRPC.
Go to Settings->writing and enable the XMLRPC checkbox.

wordpress XMLRPC api integration with ruby and rails
wordpress XMLRPC api integration with ruby and rails

Now you can fetch the wordpress posts, pages, tags etc.. using XMLRPC.

Following script is written in Ruby.

[viral-lock message=”Solution code is Hidden! It’s Visible for Users who Liked/Shared This article on Facebook or Twitter or Google+. Like or Tweet this article to reveal the content.”]

01require 'xmlrpc/client'
02 
03# build a post
04 
05#Use this for reference - http://codex.wordpress.org/XML-RPC_wp , http://codex.wordpress.org/XML-RPC_WordPress_API
06 
07post = {
08'post_title'       => 'Post Title',
09'post_excerpt'       => 'Post excerpt',
10'post_content'       => 'this is Post content'
11}
12 
13# initialize the connection - Change
14 
15connection = XMLRPC::Client.new2('http://www.purabtech.in/wordpress3/xmlrpc.php'#Replace your wordpress URL
16 
17# make the call to publish a new post
18 
19#result = connection.call('metaWeblog.getRecentPosts', 1,'admin','123456') // Get Recent 10 Post
20#result = connection.call('wp.getPost', 1,'admin','123456',19) // Get Single Post
21#result = connection.call('wp.getPage', 1,'admin','123456',1) // Get Single Page
22#result = connection.call('wp.getPages', 1,'admin','123456',10) // Get Pages
23#result = connection.call('wp.getPosts', 1,'admin','123456') // Get 10 Posts from wordpress
24result = connection.call('wp.getPosts', 1,'admin','123456',1000) // Get 10000 Posts from wordpress
25#result = connection.call('wp.newPost', 1,'admin','123456',post) //For New Creating the Post
26 
27puts result // Printresult
28puts result.length // Printresult

[/viral-lock]

If you are facing any issue then write to me.

Active Model in Rails

The technique we used was quite a hack as this is something that ActiveRecord wasn’t designed to do but now in Rails 3.0 we have a new feature called ActiveModel which makes doing something like this a lot easier.

Active Model in Rails

Before we get into the details of ActiveModel we’ll first describe the part of the application that we’re going to modify to use it.

Active Model in Rails 3.0
Active Model in Rails 3.0

The screenshot above shows a contact form that has been created using Rails’ scaffolding. The application has a model called Message that is currently backed by ActiveRecord which means that we’re managing messages through the database. We’re going to change the way this form works so that it just sends emails and doesn’t store messages in a database table.

When you’re thinking of doing something like this it’s always a good idea to first consider your requirements and make sure that you really don’t want to store the data from the form in a database as there are often good side-effects to doing this. A database can act as a backup and also makes it easier to move the message-sending into a queue in a background process. For the purposes of this example, however, we don’t want any of that functionality so we’re free to go ahead and make our model tableless.

The code for the Message class looks like this:

File name: /app/models/message.rb

1class Message < ActiveRecord::Base
2 validates_presence_of :name
3 validates_format_of :email:with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
4 validates_length_of :content:maximum => 500
5end

Message inherits from ActiveRecord::Base as you would expect a model class to, but as we don’t want this model to have a database back-end we’re going to remove that inheritance. As soon as we do this, though, our form will no longer work as the validators are provided by ActiveRecord. Fortunately, we can restore this functionality by using ActiveModel.

If we take a look at the Rails 3 source code we’ll see the that there are activerecord and activemodel directories. The core Rails team has taken everything from ActiveRecord that wasn’t specific to the database backend and moved it out into ActiveModel. ActiveRecord still relies heavily on ActiveModel for the functionality that isn’t specific to the database and as ActiveModel is full-featured and thoroughly tested it’s great for use outside ActiveRecord.

It we take a look in the directory that contains the code for ActiveModel we can see the functionality that it provides.

We can see from the list above that ActiveModel includes code to handle callbacks, dirty tracking, serialization and validation, among other things. The last of these is exactly what we’re looking for.

The code for validations has the following comment near the top and we can see from it that it’s fairly easy to add validations to a model. All we need to do is include the Validations module and provide getter methods for the attributes that we’re calling validators on.

Now that we know this we can apply it to our Message model.

File name: /app/models/message.rb

1class Message
2 include ActiveModel::Validations
3 
4 attr_accessor :name:email:content
5 
6 validates_presence_of :name
7 validates_format_of :email:with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
8 validates_length_of :content:maximum => 500
9end

Message inherits from ActiveRecord::Base as you would expect a model class to, but as we don’t want this model to have a database back-end we’re going to remove that inheritance. As soon as we do this, though, our form will no longer work as the validators are provided by ActiveRecord. Fortunately, we can restore this functionality by using ActiveModel.

If we take a look at the Rails 3 source code we’ll see the that there are activerecord and activemodel directories. The core Rails team has taken everything from ActiveRecord that wasn’t specific to the database backend and moved it out into ActiveModel. ActiveRecord still relies heavily on ActiveModel for the functionality that isn’t specific to the database and as ActiveModel is full-featured and thoroughly tested it’s great for use outside ActiveRecord.

It we take a look in the directory that contains the code for ActiveModel we can see the functionality that it provides.

We can see from the list above that ActiveModel includes code to handle callbacks, dirty tracking, serialization and validation, among other things. The last of these is exactly what we’re looking for.

The code for validations has the following comment near the top and we can see from it that it’s fairly easy to add validations to a model. All we need to do is include the Validations module and provide getter methods for the attributes that we’re calling validators on.

Now that we know this we can apply it to our Message model.

File name: /app/models/message.rb

1class Message
2 include ActiveModel::Validations
3 
4 attr_accessor :name:email:content
5 
6 validates_presence_of :name
7 validates_format_of :email:with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
8 validates_length_of :content:maximum => 500
9end

This isn’t enough to get our model to behave as the controller expects it to, though. There are two problems in the create method. Firstly the call to Message.new won’t work as our Message model no longer has an initializer that takes a hash of attributes as an argument. Secondly, save won’t work as we don’t have a database backend to save the new message to.

Filename : /apps/controllers/messages_controller.rb

01class MessagesController < ApplicationController
02 def new
03 @message = Message.new
04 end
05 
06def create
07 @message = Message.new(params[:message])
08 if @message.save
09 # TODO send message here
10 flash[:notice] = "Message sent! Thank you for contacting us."
11 redirect_to root_url
12 else
13 render :action => 'new'
14 end
15 end
16end

We’ll fix the second of these problems first. While we can’t save a message we can check that it is valid, so we’ll replace @message.save with @message.valid?.

File name :/app/controllers/messages_controllers.rb

01def create
02 @message = Message.new(params[:message])
03 if @message.valid?
04 # TODO send message here
05 flash[:notice] = "Message sent! Thank you for contacting us."
06 redirect_to root_url
07 else
08 render :action => 'new'
09 end
10end

We can solve the first problem by writing an initialize method in the Message model that takes a hash as a parameter. This method will loop through each item in the hash and assign the value to the appropriate attribute for the message using the send method.

File name: /app/models/message.rb

01class Message
02 include ActiveModel::Validations
03 
04attr_accessor :name:email:content
05 validates_presence_of :name
06 validates_format_of :email:with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
07 validates_length_of :content:maximum => 500
08 def initialize(attributes = {})
09 attributes.each do |name, value|
10 send("#{name}=", value)
11 end
12 end
13end

If we reload the form now we’ll see that we’re not quite there yet, however.

This time the error is caused by a missing to_key method in the Message model. The error is thrown by the form_for method so it seems that Rails itself is expecting our model to have functionality that it doesn’t yet support. Let’s add that functionality now.

Rather than guessing everything that Rails expects the model to have there’s a nice lint test included with ActiveModel that allows us to check whether our custom model behaves as Rails expects it to. If we include the ActiveModel::Lint::Tests module in a tests for the model it will check that the model has all of the required functionality.

The source code for the Lint::Tests module shows the methods that the model needs to respond to in order for it to work as it should, including to_key. We can make our model work by including a couple of ActiveRecord modules. The first of these is Conversion, which provides that to_key method and several others. The other module is the Naming module, but in this case we extend it in our class rather than including it as it includes some class methods.

As well as including the Conversion module we need to define a persisted? method in our model, which needs to return false as our model isn’t persisted to a database. With these changes in place our Message model now looks like this:

File name: /app/models/message.rb

01class Message
02 include ActiveModel::Validations
03 include ActiveModel::Conversion
04 extend ActiveModel::Naming
05 attr_accessor :name:email:content
06 validates_presence_of :name
07 validates_format_of :email:with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
08 validates_length_of :content:maximum => 500
09 def initialize(attributes = {})
10 attributes.each do |name, value|
11 send("#{name}=", value)
12 end
13 end
14 def persisted?
15 false
16 end
17end

If we reload the form now it will work again which means that the Message model now satisfies all of the requirements that Rails 3 relies on for a model. If we try to submit the form we’ll see that the validators are working, too.

We’ve only covered a little of what ActiveModel provides in this episode but this should have been enough to whet your appetite and give you a reason to look more deeply into its source code to see what it can do. The code is well documented and structured so if you see something you might find useful then there should be enough information in the comments for that file to get you started using it.

Ruby performance improvement of 63% in 1.9.1

Ruby is very powerful object-oriented language. new Ruby performance improvement. Working with pure Ruby is really fun and interesting to me. I am the real fan of Ruby language.

Ruby performance improvement

I am working Ruby on Rails for around last four years. There is always I am thinking and all ROR developers are thinking about performance of application.

We always compare Ruby on Rails with PHP, Java, Python, dot net. We came to know that where we are lacking in ROR. Just one issue performance and memory issue.

When we got news about Ruby 1.9 is comming with performance improvement of 63%. Yes, It is not a joke. This is really great news for every ROR developers. Ruby 1.9 and Rails 3.0 is the future of internet.

Now I will talk about Ruby Software engineer who developed and worked on the Ruby 1.9.

Masahiro Kanai, who improved the performance of several methods in Ruby 1.9. He is the age of high school, just 17.

This year, Ruby 1.9 by the Fibonacci sequence of operations (multiple-precision addition) is,
Ruby 1.8 is slower than I realized Mr. Kanai is a challenge to freedom of choice camp Ruby faster.

In front of all the participants had a similar problem occurring, Ruby of type String, Array types (structures that may have an embedded data structure type object itself) and some of the faster method, attention collection. Oden’s is known to be well-covered tongue teachers. Ruby continued even after the camp’s efforts to speed up to approximately some methods to remove the macro in a constant loop of 63 percent to about 8 percent of success in speeding. This patch has been adopted by the community of developers Ruby, Ruby has been incorporated into the trunk (October 5, 2009).

many professional engineers and developers, with patience to hold out that the problem is resolved, probably as a programmer in one or two talents.

Ketai that builds skills and career tips for the professional engineer. Interviewers are already familiar with this series, the Mr. Ikuo Takeuchi, Professor Department of Creative Informatics, Graduate School of Information Science and Engineering, University of Tokyo. This time, who undertook the voluntary and discover if training for a talented programmer.

His mentor was Koichi Sasada (ko1). The performances of the methods he worked have been bumped up 63% in maximum, 8% in average. His patches were applied to Ruby trunk in Oct. 5 this year.

What he did for Ruby Performance tuning?

He took unnecessary macro references out from a loop. Masahiro spotted macros below in array.c, string.c, and struct.c were referred every time Ruby checked whether data was hold in a structure or not. Even though data were constants, Ruby saw the macros to judge data’s presence in every loop.

What I say now more… I am really happy and I can say this is the biggest news of 2010 in IT world.

One thing I want to mention here about Ruby on Rails. This thing is in mind of all ROR developers.

“Thank God, No need to look Jruby”

He took unnecessary macro references out from a loop. Masahiro spotted macros below in array.c, string.c, and struct.c were referred every time Ruby checked whether data was hold in a structure or not. Even though data were constants, Ruby saw the macros to judge data’s presence in every loop.

Rails 3 beta by February

Rails 3 beta by February, Ruby on Rails 3, an upgrade to the popular Web development framework that merges Rails with the alternative Merb framework, is due to be offered as a beta release by the end of this month.

ruby_on_rails_logo
Rails 3 beta by February, Ruby on Rails 3, an upgrade to the popular Web development framework that merges Rails with the alternative Merb framework, is due to be offered as a beta release by the end of this month.

Rails 3 beta by February

According to David Heinemeier Hansson, the founder of the Ruby based web development framework, although a beta of Rails 3 is expected by the end of this month the release may slip into February. Hansson gave the estimated release timing in an article on InfoWorld. If all goes to plan Rails 3 is expected to arrive in the first quarter of this year. Rails 3 is a major reworking of the framework which sees ideas from the alternative Merb framework being integrated in a development process which began in December 2008.

Source Articles

http://www.engineyard.com/blog/2009/my-five-favorite-things-about-rails-3/

How to host multiple rails site on Nginx

Nginx famous now. We given information for how to host multiple rails site on Nginx. we given the configuration code along with their detailed information.

How to host multiple rails site on Nginx

User following code in Nginx.conf file.. and paste into that file.
#vim /etc/nginx/nginx.conf

01http {
02include       /etc/nginx/mime.types;
03default_type  application/octet-stream;
04access_log  /var/log/nginx/access.log  main;
05sendfile        on;
06 
07upstream mongrel_cluster_example1 {
08server 127.0.0.1:8000;
09server 127.0.0.1:8001;
10server 127.0.0.1:8002;
11}
12 
13upstream mongrel_cluster_example2 {
14server 127.0.0.1:3000;
15server 127.0.0.1:3001;
16server 127.0.0.1:3002;
17}
18 
19# Load config files from the /etc/nginx/conf.d directory
20include /etc/nginx/conf.d/*.conf;
21 
22server {
23listen       80;
24server_name  example1.com example2.net;
25client_max_body_size 120M;
26 
27set $myroot /var/www/html;
28if ($host ~* example1\.com$) {
29set $myroot /home/example1/public;
30}
31 
32if ($host ~* example2\.net$) {
33set $myroot /home/example2/public;
34}
35 
36root $myroot;
37 
38location ~* ^/(images|stylesheets|javascripts).+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$
39{
40root $myroot;
41}
42 
43location / {
44 
45if ($host ~* example1\.com$) {
46proxy_pass      http://mongrel_cluster_example1;
47} #if check for domain qa.teenangel ends here
48 
49if ($host ~* example2\.net$) {
50root /home/rail_project/myproject/public;
51proxy_pass      http://mongrel_cluster_example2;
52 
53} #if check for domain ends here
54 
55}
56 
57}
58 
59}

USA State list for Rails

Every time we need this migration script for our projects
Use following command for Model generate
[siwan@localhost siwan]$ ruby script/generate model UsStates
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/us_states.rb
create test/unit/us_states_test.rb
create test/fixtures/us_states.yml
exists db/migrate
create db/migrate/20091117115011_create_us_states.rb
[siwan@localhost siwan]$

Open the /db/migrate/20091117115011_create_us_states.rb file and paste following code:

class CreateUsStates ‘Alabama’, :abbreviation => ‘AL’
UsStates.create :name => ‘Alaska’, :abbreviation => ‘AK’
UsStates.create :name => ‘Arizona’, :abbreviation => ‘AZ’
UsStates.create :name => ‘Arkansas’, :abbreviation => ‘AR’
UsStates.create :name => ‘California’, :abbreviation => ‘CA’
UsStates.create :name => ‘Colorado’, :abbreviation => ‘CO’
UsStates.create :name => ‘Connecticut’, :abbreviation => ‘CT’
UsStates.create :name => ‘Delaware’, :abbreviation => ‘DE’
UsStates.create :name => ‘District of Columbia’, :abbreviation => ‘DC’
UsStates.create :name => ‘Florida’, :abbreviation => ‘FL’
UsStates.create :name => ‘Georgia’, :abbreviation => ‘GA’
UsStates.create :name => ‘Hawaii’, :abbreviation => ‘HI’
UsStates.create :name => ‘Idaho’, :abbreviation => ‘ID’
UsStates.create :name => ‘Illinois’, :abbreviation => ‘IL’
UsStates.create :name => ‘Indiana’, :abbreviation => ‘IN’
UsStates.create :name => ‘Iowa’, :abbreviation => ‘IA’
UsStates.create :name => ‘Kansas’, :abbreviation => ‘KS’
UsStates.create :name => ‘Kentucky’, :abbreviation => ‘KY’
UsStates.create :name => ‘Louisiana’, :abbreviation => ‘LA’
UsStates.create :name => ‘Maine’, :abbreviation => ‘ME’
UsStates.create :name => ‘Maryland’, :abbreviation => ‘MD’
UsStates.create :name => ‘Massachutsetts’, :abbreviation => ‘MA’
UsStates.create :name => ‘Michigan’, :abbreviation => ‘MI’
UsStates.create :name => ‘Minnesota’, :abbreviation => ‘MN’
UsStates.create :name => ‘Mississippi’, :abbreviation => ‘MS’
UsStates.create :name => ‘Missouri’, :abbreviation => ‘MO’
UsStates.create :name => ‘Montana’, :abbreviation => ‘MT’
UsStates.create :name => ‘Nebraska’, :abbreviation => ‘NE’
UsStates.create :name => ‘Nevada’, :abbreviation => ‘NV’
UsStates.create :name => ‘New Hampshire’, :abbreviation => ‘NH’
UsStates.create :name => ‘New Jersey’, :abbreviation => ‘NJ’
UsStates.create :name => ‘New Mexico’, :abbreviation => ‘NM’
UsStates.create :name => ‘New York’, :abbreviation => ‘NY’
UsStates.create :name => ‘North Carolina’, :abbreviation => ‘NC’
UsStates.create :name => ‘North Dakota’, :abbreviation => ‘ND’
UsStates.create :name => ‘Ohio’, :abbreviation => ‘OH’
UsStates.create :name => ‘Oklahoma’, :abbreviation => ‘OK’
UsStates.create :name => ‘Oregon’, :abbreviation => ‘OR’
UsStates.create :name => ‘Pennsylvania’, :abbreviation => ‘PA’
UsStates.create :name => ‘Rhode Island’, :abbreviation => ‘RI’
UsStates.create :name => ‘South Carolina’, :abbreviation => ‘SC’
UsStates.create :name => ‘South Dakota’, :abbreviation => ‘SD’
UsStates.create :name => ‘Tennessee’, :abbreviation => ‘TN’
UsStates.create :name => ‘Texas’, :abbreviation => ‘TX’
UsStates.create :name => ‘Utah’, :abbreviation => ‘UT’
UsStates.create :name => ‘Vermont’, :abbreviation => ‘VT’
UsStates.create :name => ‘Virginia’, :abbreviation => ‘VA’
UsStates.create :name => ‘Washington’, :abbreviation => ‘WA’
UsStates.create :name => ‘West Virginia’, :abbreviation => ‘WV’
UsStates.create :name => ‘Wisconsin’, :abbreviation => ‘WI’
UsStates.create :name => ‘Wyoming’, :abbreviation => ‘WY’

end

def self.down
drop_table :us_states
end
end

Goodlunk, This code will save your problem of fetching USA state names and abbreviations as per id

Check my controller code…Just put in your controller

@us_states = USStates.find(:all)

<% form_for :customer, @customer, :url => { :action => “new_application” } do |f| %>
<%= f.select :state_id,  @us_states.collect {|state| [ state.abbreviation, state.id ] } %>
<% end %>

Issue with installing the mysql gem: solved, how to install mysql gem without issue

When tried to install mysql gem I got following error
[root@localhost siwan]# sudo gem install mysql
Building native extensions. This could take a while…
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb
checking for mysql_ssl_set()… yes
checking for rb_str_set_len()… no
checking for rb_thread_start_timer()… yes
checking for mysql.h… no
checking for mysql/mysql.h… no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
–with-opt-dir
–without-opt-dir
–with-opt-include
–without-opt-include=${opt-dir}/include
–with-opt-lib
–without-opt-lib=${opt-dir}/lib
–with-make-prog
–without-make-prog
–srcdir=.
–curdir
–ruby=/usr/bin/ruby
–with-mysql-config
–without-mysql-config

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out

To find the mysql path on machine used following command
[root@localhost siwan]# which mysql
/usr/bin/mysql

I tried following command:
[root@localhost siwan]# sudo gem install mysql — –with-mysql-dir=/usr/bin/mysql

I Got the same error

[root@localhost siwan]# sudo gem install mysql — –with-mysql-dir=/usr/bin/mysql
Building native extensions. This could take a while…
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb
checking for mysql_ssl_set()… yes
checking for rb_str_set_len()… no
checking for rb_thread_start_timer()… yes
checking for mysql.h… no
checking for mysql/mysql.h… no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
–with-opt-dir
–without-opt-dir
–with-opt-include
–without-opt-include=${opt-dir}/include
–with-opt-lib
–without-opt-lib=${opt-dir}/lib
–with-make-prog
–without-make-prog
–srcdir=.
–curdir
–ruby=/usr/bin/ruby
–with-mysql-config
–without-mysql-config

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
ERROR: could not find gem — locally or in a repository
ERROR: could not find gem –with-mysql-dir=/usr/bin/mysql locally or in a repository

Then I checked the mysql-devel
[root@localhost siwan]# yum list mysql-devel
Loaded plugins: refresh-packagekit
Available Packages
mysql-devel.i586 5.1.37-1.fc11 updates

Then I Installed the mysql-devel
[root@localhost siwan]# yum install mysql-devel
Installed:
mysql-devel.i586 0:5.1.37-1.fc11
Complete!

Then I tried the mysql Gem installing…..I am able to install the mysql gem…
[root@localhost siwan]# gem install mysql
Building native extensions. This could take a while…
Successfully installed mysql-2.8.1
1 gem installed
Installing ri documentation for mysql-2.8.1…
Installing RDoc documentation for mysql-2.8.1…
[root@localhost siwan]#

How to setup mongrel cluster setup on fedora

First install the following gems:
#su
#gem install mongrel
#gem install mongrel_cluster
#cd project_name
#mongrel_rails cluster::configure -e production -p 3000 -N 3 -c /home/siwan/project_name -a 127.0.0.1 —-prefix /project_name
# mongrel_rails cluster::start

You are able to start your applicaton at http://127.0.0.1:3000, http://127.0.0.1:3001 and http://127.0.0.1:3002

for all the cluster
# mongrel_rails cluster::stop

Advanced prepairation for production realeaze
$ mkdir /etc/mongrel_cluster

#vim /etc/mongrel_cluster/project_name.yml
copy and paste following text;
user: project_name
cwd: //home/siwan/project_name
log_file: /home/siwan/project_name/mongrel.log
port: “3000”
environment: production
group: dev
address: localhost
pid_file: /home/siwan/project_name/tmp/pids/mongrel.pid
servers: 3

or you can run the following command

or copy and paste the content from config/mongrel_cluster.yml file to /etc/mongrel_cluster/project_name.yml

# ln -s /home/siwan/project_name/config/mongrel_cluster.yml /etc/mongrel_cluster/project_name.yml

Then open your httpd.conf file for apache configration:

<Proxy balancer://project_name>
BalancerMember http://127.0.0.1:3000
BalancerMember http://127.0.0.1:3001
BalancerMember http://127.0.0.1:3002
</Proxy>

<VirtualHost *:80>
ProxyPreserveHost On
# Avoid open you server to proxying
ProxyRequests Off
# Options +FollowSymLinks
RewriteEngine On

RewriteRule ^/(images|stylesheet|javascript|html)/?(.*) /home/siwan/project_name/public/$0 [L]
ServerAdmin siwan@yahoo.co.in
DocumentRoot /home/project_name/
ServerName example.com
RewriteRule  ^/(.*)$  balancer://project_name%{REQUEST_URI} [P,QSA,L]
</VirtualHost>

Restart the apache server
#/etc/init.d/httpd restart

Command for restart the mongrel servers from any where
# mongrel_rails cluster::restart -C /etc/mongrel_cluster/project_name.yml

Use PHP in Rails project

Many times you need to use PHP scripts in Rails project. You will got so much open source PHP scripts for various use.

Example is So many Rails site is using WordPress for blogging system.

Main reason behind using PHP files or script is SEO. PHP is a very SEO friendly.

Customer does not want to spend money or time already existing scripts or program.

If you want to use PHP files or project under Rails project. Just create any folder in Public directory and put your php files in to that folder.

lets say you created the “fourm” dir in public directory.

You need to add following lines in your apache rule file(httpd.conf)

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_http_module modules/mod_proxy_http.so

Under <VirtualHost  *:80> tag add following lines:

ProxyRequests Off

RewriteEngine On

RewriteCond  %{HTTP_HOST}    ^example.com [NC]
RewriteCond %{REQUEST_URI}  !^/forum(.*)$ [NC]

RewriteCond  %{HTTP_HOST}    ^example.com [NC]

RewriteRule ^/forum/?(.*)$ /document_root/forum/$1 [QSA,NC,L]

Than you are able to use PHP code or scripts in Rails project

How to use juggernaut in Rails project

Juggernaut is the Rails plugin for sending and receiving data in different thread. It gives you real time connection to server and you can implement different ideas work or fulfil your requirement.

Juggernaut uses the eventmachine as a server.

So install the supported gem first.

#gem install json

#gem install eventmachine

#gem install juggernaut

Juggernaut is aims to revolutionize your Rails app by letting the server initiate a connection and push data to the client.

Juggernaut is used for speciallycreating Chat application.

If you want to full details about Juggernaut then go to http://juggernaut.rubyforge.org/

First install the juggernaut to your application using this command.
ruby script/plugin install git://github.com/maccman/juggernaut_plugin.git

install the gem : gem install juggernaut

Configure the gem: juggernaut –g juggernaut.yml

Start the Juggernaut server: juggernaut -c juggernaut.yml

(This is not rails server or mongrel server)

In your controller you can use this method to send data to Juggernaut server

Juggernaut.send_to_all(“alert(‘hi from juggernaut’)”)

If you want customize the Juggernaut methods or add new methods then open file:

/vender/plugin/juggernaut_plugin/lib/juggernaut.rb

Add your methods there and use in your projects.