Skip to content

Simple News and events in drupal block


This is the php code for create a simple news and event in page or block in drupal.

<marquee direction="up" width="20%" height="30%" onmouseover="this.setAttribute('scrollamount', 0, 0);" onmouseout="this.setAttribute('scrollamount', 6, 0);">
global $base_path;
$res = db_query('SELECT title,nid FROM node WHERE type="image_gallery" ORDER BY nid  DESC LIMIT 0 , 6');
$img="<img src=''/>";
while ($row = db_fetch_array($res)) {
if($count>3){ $img="";}
echo "<a href='?q=node/".$row['nid']."'>".$row['title'].$img."</a>"."<br>";


First create a content type name as “News”. Then create a pages in news content type. Now we want to get the news content type title (News event title) from the database,And display as block or page. Enable the “Phpfilter” module, now we can see new input format, in a page or new block past the code and choose the input format as php. Now it will show as,

நன்றி …



Start to learn Drupal


today i simply start to learn  Drupal. i download Drupal-6 from drupal site

Then followed the necessary steps to install the Drupal  in my laptop.

i hope, i will create a good  site soon…..

i completed MCA!!


i have completed my MCA Degree..

i enjoyed and learned lot of things in my college life. i do not know how college life moved.

i miss my college life…..

i miss my college friends…..


Error while installing nokogiri gem

I try to install nokogiri gem in rails3, i faced following error

nokogiri requires two libraries as libxslt-dev,libxml2-dev

sudo apt-get install libxslt-dev libxml2-dev

Then install nokogiri,

sudo gem install nokogiri

now its installed fine. to know more visit here,




Destroy not working in rails

in my rails application i changed my JavaScript connection in my application.html.erb


<%= javascript_include_tag :default %>

i include my new jquery file like

<%= javascript_include_tag '' %>

now in my application destroy function not working while i click destroy button it goes to edit page.

then some struggle i got the inner JavaScript function need default JavaScript file such as jquery.js and rails.js .

just include the both file in application.html.erb file like

<%= javascript_include_tag '','jquery','rails' %>

now its works successfully..


Nested module form in rails3

Today i learn Nested module in rails using Javascript and Ajax. here i share what i created .

This is the tour program form for  MSR to visit Doctors.

first create the rails application adapted by mysql and set its user and password in database.yml file.

here i used three modules by crating scaffold.

create Tourplane scaffold with necessary fields.

rails g scaffold Tourplane name:string form:date to:date

create Hospital scaffold with necessary fields.

rails g scaffold Hospital tourplane:references name:string location:string

create Doctors scaffold with necessary fields.

rails g scaffold Doctors hospital:references name:string phone:integer

then set the relationship of those modules.

Tourplan has many hospital to visit so enable the nested modules.

class Tourplane < ActiveRecord::Base
 has_many :hospitals
 accepts_nested_attributes_for :hospitals

Hospital has many doctors so need nested module to add and also hospital belongs to Tourplane

class Hospital < ActiveRecord::Base
 belongs_to :tourplane
 has_many :doctors
 accepts_nested_attributes_for :doctors

Doctors only belongs to Hospitals.

class Doctor < ActiveRecord::Base
 belongs_to :hospital

All relations are set now can create database and crate table

rake db:create
rake db:migrate

now start the server open the Tourplanes in server it shows like.

To set nested module we need ajax server call so include the jquery library.
download the unzip file from and include file in /javascript/jquery.js
it is the library for jquery method.
To active jquery file set the link in application.erb. and also i write my script in mtscript file

<%= javascript_include_tag 'jquery','myscript' %>

now set the Hospital link in Tourplanes/new  and while click this link catch the hospital/new include in this page for that we use helper method to set link.

Write the method to set the link in tourplane_helper.rb

module TourplanesHelper
 def add_hospital_link(name)
 link_to name, '#', :class => "add_hospital"

class name set for this for catch this method in jquery.

Then call the method from tourplane/_form.html.erb

 <%= add_hospital_link("Add Hospital") %>

Now check it will set the link like

Then catch the method in jquery and call the ajax call to server

 alert('it works');

It call the url link to routes now we match the link and set the routes in /config/routes.rb

Tourplanner::Application.routes.draw do
 resources :doctors
 resources :hospitals
 match 'tourplanes/add_hospitals' => 'tourplanes#add_hospitals'
 resources :tourplanesend

Then it call to<strong> /app/controllers/tourplanes_controller.rb </strong>file method name <strong>add_hospitals. </strong>create the method set the partial and create the hospital object pass to that partial file. like<strong>

def add_hospitals
 render :partial => 'hospital', :locals => {:hospital_object =>}

Then render the hospital field here. For that we have to create partial file in /views/tourplanes/_hospital.html.erb . and include like.

 <%= fields_for "tourplane[new_hospital_attributes[]]",hospital_object do |hospital| %>  # new_hospital_attributes is a method call tourplane.rb to insert multi record into hospital table from the tourplane
 <%= "Hospital Name" %>
 <%= hospital.text_field :name %>
 <% end %>

Now the server create the new file in hospital. catch the data and pass to the view. to catch the passed data in view create the empty div tag in /view/tourplanes/_form.html.erb

<div class="result_hospital">


Catch the passed data by ajax success method and pass to view by using that class name. in myscript add like this

 alert('it works');

now run the application and click the hospital it will add the text box for hospital like this

Then, to store the hospital value in hospitals table create the method to build multi record in /app/models/tourplane.rb

class Tourplane < ActiveRecord::Base
 has_many :hospitals
 accepts_nested_attributes_for :hospitals
 def new_hospital_attributes=attributes
 attributes.each do |record|

now run the application and add multi hospitals and create like

see your server it show like

now the both toueplane and hospital record saved successfully in database.

but in show method shows tourplane values only.

To show hospital values set in _form.html.erb file as

 <% for hospital in @tourplane.hospitals %>
 <li> <%= %></li>
 <% end %>

now show displays the hospital this

Jquery on Rails

today Mr.Thiyagarajan took class how to include jquery file in rails and how to use the file in our rails application.

my works on jquery.

in my rails application i used scaffold javascript file only. To use jquery first include the jquery library. download the latest version of jquery from .

To use jquery in rails application past the jquery download file in to /public/javascript . set the link in /app/views/layout/application.html.erb as

<%= javascript_include_tag 'jquery-1.5.1' %>  #include jquery file name no need extension.

for check jquery works write own jquery file and include into application.html.erb.

set class or id in _form to any one tag example

 <%= f.label :phone %><br />
 <%= f.text_field :phone, :id => 'customer_phone'%>
 <%= f.label :email %><br />
 <%= f.text_field :email, :class => 'customer_email'%>

catch these class and id in jquey file like

myjquery.js include the file in application.html.erb <%= javascript_include_tag ‘jquery-1.5.1′,’myjquery’ %>

alert('jquery works for "id"');
alert('jquery works for "class"');

now start the rails server and open the application url in browser.

click the phone text box it will show like

i set the ‘id’ for phone text box and catch into the myjquery.js set alert for that.

then click the email text box it will show like

i set the ‘class‘ for phone text box and catch into the myjquery.js set alert for that.

this is the easy way to include jquery file in rails application.

id => id name is a unique name for a tag.

class => class name can set multiple tag