Feeds:
Posts
Comments

The Eyes

Eyes have one language everywhere…..

eyes

Create a controller with the name ‘sitemap’ (or) with the name you desire…..

(E.g)
ruby script/generate controller sitemap
(or)
You can manually create one [app/controllers/sitemap_controller.rb]

When you view the ‘controller file’ which you created just now, it would look like;

class SitemapController < ApplicationController
end

Once it’s done, we need to add the functionality to the controller,to generate the urls dynamicallly.

Here, I am forming the urls, based on the fileds from “Category” and “Language” tables in the database. You may need to form different custom url formats. Do it as per your requirement here.

I am doing that through, ‘generate_url()’ function. This method does the following;

1)Retreives all the url fields(categories) from database [@categories = Category.find(:all)]

2)Forms the ‘url format’ [temp_url += "/category/#{slugify(category.name)}"] and adding it to the “Array field” [url.push(temp_url)]

3)The method ‘slugify()’ removes white-spaces, all unnecessary characters and gives you the ‘url supported string’. (e.g) slugify(‘all languages’) will return ‘all-languages’

The final controller code will look like;

class SitemapController < ApplicationController
caches_page :index
def index
headers["Content-Type"] = “text/xml”
@url_collection = generate_url()
end

def generate_url
url = Array.new

@categories = Category.find(:all)
@languages = Language.find(:all)
if @categories != nil && @categories != “”
@categories.each do |category|
temp_url = “”
temp_url += “/category/#{slugify(category.name)}”
url.push(temp_url)
end
end
if @languages != nil && @categories != “”
@languages.each do |language|
temp_url = “”
temp_url += “/language/#{slugify(language.name)}”
url.push(temp_url)
end
end
return url
end

def rebuild
expire_page :action => “index”
redirect_to :action => “index”
end

def slugify(text)
return text.downcase.gsub(/&/, ‘ and ‘).gsub(/[^a-z0-9']+/, ‘-’).gsub(/^-|-$|’/, ”)
end
end

The ‘index()’ function here sets the ‘content-type’ to “text/xml” and then calls our ‘generate_url’ function

Also, you may note, ‘caches_page :index’ in the beginning of the line. This is to cache the ‘sitemap’ output, so that the ‘sitemap’ controller is not called every time. The cached output ‘sitemap.xml’ can be found at ‘RAILS_ROOT/public’ folder. When you clear this file(sitemap.xml) in the ‘public’ folder, the sitemap controller will be called again to generate the sitemap again. It’s always the best chocie to cache the sitemap.

To clear the cache and rebuild the sitemap, just invoke;

http://<hostname>/sitemap/rebuild

The next step is to make a ‘view’ to show the output. Make the ‘app/views/sitemap/index.rxml’ file to look like the following one;

xml.instruct!
xml.urlset “xmlns” => “http://www.sitemaps.org/schemas/sitemap/0.9″ do
@url_collection.each do |url|
xml.url do
xml.loc url
xml.lastmod Date.today
xml.changefreq ‘weekly’
xml.priority 0.5
xml.size @url_collection.length
end
end
end

You may also like to add this in your’config/routes.rb’;

map.connect ‘sitemap.xml’, :controller => “sitemap”, :action => “index”

You should see the sitemaps in;

http://<hostname>/sitemap

http://<hostname>/sitemap.xml

If you are trying to run the script in an updated div, that may work with the internal scripts – something like;

<script type=”text/javascript”>
alert(‘hello’);
</script>

But when you try to access some external javascrips, (e.g);

<script type=”text/javascript”>
<script type=”text/javascript” src=”/javascripts/my_script.js”></script>
</script>

that will not work.

The work-around is;

[if you are using mootools.js for making ajax calls]  /  for other frame-works, check how to set ‘evalScripts’ param

1) First step is to, add

“evalScripts: true” param

(E.g)

new Ajax(url, {
method: ‘get’,
update: $(‘content’),
evalScripts: true
}).request();

2) Then in the div, make the javascript look like;

<script type=”text/javascript”>
new Asset.javascript(‘/javascripts/my_script.js’);
</script>

(or)

Load the javascript dynamically like this; [if 'Asset.javascript' is not supported]

<script id=”external_script” type=”text/JavaScript”></script>
<script>
document.getElementById(‘external_script’).src = ‘/javascripts/my_script.js’;
</script>

Experience

Experience is a kind of teacher; who gives the test first before presenting the lesson.

View from the HillIt was a quick decision to go to some place to relax, and atlast we came to a conclusion to visit “Nandi Hills”. It’s about 70 kms from Bangalore. We started in two unicorn bikes from Madiwala. Decided to go via Hebbal. Had a cup of coffee at ‘Devanahalli’ for a break, and continued the trip.

sdc139571Thank God, we got good climate on that day and reached ‘Nandi Hills’ without any hassle. The place was good more than the expectation. The bike ride on that small hill was really a thrilling one. Hesitated to pay the entry and parking charges, but after seeing the beautiful garden and the flowers inside felt like, they can charge more.

Snacks TimeA karnataka tourism’s hotel and a private one is there, so no need to worry, whether we will get Briyani or not ;) ?. Decided to leave by 3 PM and to land directly at Cubbon Park. But the village beauty made us to settle under a tree. Finished all the snacks there and returned to Bangalore with the as-usual discussion, “where is the next trip?”. But we are sure we will make the next trip at the earliest.

Suggestion: Don’t try by bike during summer.
Food: No issues.
Distance: Abt 70kms from Bangalore.
Total distances covered: Abt 160-170kms
Roadways: Awesome. National highways till Devanahalli and then u get a good village road with beautiful surroundings.

More Photos

Who is at Risk?

A mouse looked through a crack in the wall to see the farmer and his wife opening a package; what food might it contain? He was surprised to discover that it was a mouse trap! Retreating to the farmyard, the mouse proclaimed the warning, “There is a mouse trap in the house, there is a mouse trap in the house.”

The chicken clucked and scratched, raised her head and said, “Mr. Mouse, I can tell you this is a grave concern to you, but it is of no consequence to me; I cannot be bothered by it.”

The mouse turned to the pig and told him, “There is a mouse trap in the house.” “I am so very sorry Mr. Mouse,” sympathized the pig, “but there is nothing I can do about it but pray; be assured that you are in my prayers.”

The mouse turned to the cow, who replied, “Like wow, Mr. Mouse, a mouse trap; am I in grave danger, Duh?”

So the mouse returned to the house, head down and dejected to face the farmer’s mouse trap alone.

That very night a sound was heard throughout the house, like the sound of a mouse trap catching its prey. The farmer’s wife rushed to see what was caught. In the darkness, she did not see that it was a venomous snake whose tail the trap had caught. The snake bit the farmer’s wife.The farmer rushed her to the hospital. She returned home with a fever.

Now everyone knows you treat a fever with fresh chicken soup, so the farmer took his hatchet to the farmyard for the soup’s main ingredient.
His wife’s sickness continued so that friends and neighbors came to sit with her around the clock.
To feed them, the farmer butchered the pig. The farmer’s wife did not get well, in fact, she died, and so many people came for her funeral the farmer had the cow slaughtered to provide meat for all of them to eat.

So the next time you hear that someone is facing a problem and think that it does not concern you, remember that when the least of us is threatened, we are all at risk.

A turtle family went on a picnic.. The turtles, being naturally slow about things, took seven years to prepare for their outings.Finally the turtle family left home looking for a suitable place. During the second year of their journey they found it. For about six months theycleaned up the area, unpacked the picnic basket, and completed the arrangements.

Then they discovered the had forgotten the salt. A picnic without salt would be a disaster, they all agreed. After a lengthy discussion, the youngest turtle was chosen to retrieve the salt from home.

Although he was the fastest of the slow moving turtles, the little turtle whined, cried, and wobbled in his shell. He agreed to go on one condition: that no one would eat until he returned. The family consented and the little turtle left.

Three years passed– and the little turtle had not returned. Fiveyears…six years.. then in the seventh year of his absence, the oldest turtle could no longer contain his hunger. He announced that he was going to eat and began to unwrap a sandwich.

At that point the little turtle suddenly popped out from behind a tree shouting, “SEE I knew you wouldn’t wait. Now I am not going to go get the salt.”

The Moral Is…Some of us waste our lives waiting for people to live up to our expectations of them. We are so concerned about what others are doing that we don’t do anything ourselves. There are times you need to depend on others and not to. But, Don’t depend on others for everything

Once there was a king who told some of his workers to dig a pond. Once the pond was dug, the king made an announcement to his people saying that one person from each household has to bring a glass of milk during the night and pour it into the pond. So, the pond should be full of milk by the morning.
After receiving the order, everyone went home. One man prepared to take the milk during the night. He thought that since everyone will bring milk, he could just hide a glass of water and pour inside the pond. Because it will be dark at night, no one will notice. So he quickly went and poured the water in the pond and came back.

In the morning, the king came to visit the pond and to his surprise the pond was only filled with water! What has happened is that everyone was thinking like the other man that “I don’t have to put the milk, someone else will do it.”

Dear friends, when it comes to help poor people, do not think that others will take care of it. Rather, it starts from you, if you don’t do it, no one else will do it. So, change yourself and make the difference.

Kids answer

Teacher: Frank, how old were you last year?
Frank: 7 years old
Teacher: Then how old you will be next year?
Frank: 9 years old
Teacher: That’s impossible!
Frank: No, it isn’t, today is my birthday!

Rails comes with a script/runner script that can be used to run the code in your Rails app. There’re many ways to organize your code to let this runner script execute it, but one obvious way is to write the code as a model’s action.
Here are quick steps for doing this:

1. Insert the code into an action of a model,

(E.g) Model.MyFunction, “MyFunction” must be defined as class method, “def self.MyFunction…”

2. In your cron job, add a line to run this at certain interval:

/usr/local/bin/ruby /path/to/your/app/script/runner -e production “Model.MyFunction”

You may need to change the ruby path on your system if it is different.

« Newer Posts - Older Posts »