Skip to content

Simple News and events in drupal block


hi,

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);">
<?php
global $base_path;
$res = db_query('SELECT title,nid FROM node WHERE type="image_gallery" ORDER BY nid  DESC LIMIT 0 , 6');
$count=0;
$img="<img src='http://cdachyd.in/new_icons_10.gif'/>";
while ($row = db_fetch_array($res)) {
$count++;
if($count>3){ $img="";}
echo "<a href='?q=node/".$row['nid']."'>".$row['title'].$img."</a>"."<br>";

}
?>
</marquee>

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


hi,

today i simply start to learn  Drupal. i download Drupal-6 from drupal site http://drupal.org/download.

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

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

i completed MCA!!


hi,

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,

http://nokogiri.org/tutorials/installing_nokogiri.html

thanks…

 

 

Destroy not working in rails


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

before


<%= javascript_include_tag :default %>

i include my new jquery file like


<%= javascript_include_tag 'jquery.mobile-1.0a1.min' %>

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.mobile-1.0a1.min','jquery','rails' %>

now its works successfully..

thanks…

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
end

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
end

Doctors only belongs to Hospitals.

class Doctor < ActiveRecord::Base
 belongs_to :hospital
end

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 http://jquery.com 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"
 end
end

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

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


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

Now check it will set the link like


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


$(document).ready(function(){
 $('.add_hospital').click(function(){
 alert('it works');
 $.ajax({
 method:"POST",
 url:'/tourplanes/add_hospitals',
 data:"",
 });
 });
});

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>
</strong>


def add_hospitals
 render :partial => 'hospital', :locals => {:hospital_object => Hospital.new}
 end

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


<div>
 <%= 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 %>
</div>

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">

 </div>

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

$(document).ready(function(){
 $('.add_hospital').click(function(){
 alert('it works');
 $.ajax({
 method:"POST",
 url:'/tourplanes/add_hospitals',
 data:"",
 success:function(data){
 //$('.hospital_result').html(data);
 $(data).appendTo('.hospital_result');
 }
 });
 });
});

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|
 hospitals.build(record)
 end
 end
end

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


<p>
Hospital
<ol>
 <% for hospital in @tourplane.hospitals %>
 <li> <%= hospital.name %></li>
 <% end %>
 <ol>
 </p>

now show displays the hospital values.like 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 http://jquery.com/ .

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


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

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’ %>


$(document).ready(function(){
$('#customer_phone').click(function(){
alert('jquery works for "id"');
});
$('.customer_email').click(function(){
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

thanks…