rails wonderful content_tag method for easy html markup

I always hate to write basic HTML tags in view files as they are  much more complex to write and the angle brackets with close/open HTML tags make the readability very worst. I became much happy when i come to know that rails is providing wonderful ‘content_tag’ method by default for clean and easy HTML markup implementation.


content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block)


Here,
name:   name of html tag
content_or_options_with_block:   content to be placed in html tag(default is nil)
options:   hash for adding html attributes

Examples:
content_tag(:div, "Hello Rails!")
   # => Hello Rails!
content_tag(:div, content_tag(:p, "How Are You?"), :class => "status_msg")
   # =>  <div class="status_msg"><p>How Are You?</p></div>


We can use it as a block by passing the ‘options’ as a second parameter. Eg:


<% content_tag :span, :class => "side_footer" do -%>
    I love Rails!
<% end -%>


I used it in one of my project to make user’s navigation bar :


def user_navigation_bar
 content_tag(:div, :class =>"top_banner") do
   if current_user
     content_tag(:li) { current_user.username}
     content_tag(:li) { link_to("Edit Profile", edit_user_path(:current)) }
     content_tag(:li) { link_to("Logout", logout_path) }
   else
     content_tag(:li) { link_to("Login", login_path) }
     content_tag(:li) { link_to("Signup", new_user_path) }
   end
  end
end


Vow,  it is easy to read with lot of  DRYness. I also like http://haml-lang.com for generating clean, semantic markups.

Place Pages – A new google maps product

Half a decade before, when i was studying in Haridwar, UK-India, i always need to come New Delhi (capital of India) for tours, picnics & various entrancce exams. So, before entering in capital, i were always buy a Atlas (a map book) of N.Delhi because it’s world’s one of the largest city having too much crowd and very networked city.

So, i always need to explore the places( historical buildings, colleges for exams, markets for shopping etc.). But i always found Atlas has very limited information which i want. Sometimes i need to consult with delhities (delhi’s localized people) for awareness of any place.

I was always very thankful of google to launch google maps.It was a wonderful place for exploring places anywhere in the world. With google maps, i can wonderfully zoom the maps for close look, can search nearby places, can see street views etc, some images of popular images with markers on the map.So, purpose of google map has always been to help the people to find information easily without exploring the whole web.
Last week google launched Google Place Pages on google maps.A Place Page is a web page for every place in the world, organizing all the world’s information for that place.There are Place Pages for businesses, historical places, points of interest, stations and airports, landmarks, and cities all over the world.

gmapinfo-1

Now we can get to a Place Page by just clicking on “more info >>“ in search results, or by clicking “more info” in

the mini-bubble.

gmapinfo-2

Here one can find Photos & Videos, popular places , map image with marker pointing to your location, reviews by other visitors etc.

gmapinfo-3

But there are some questions in my mind after seeing this enhancement made by google -

1.   Is google trying to resisting the visitors to navigate to other related travel site where one can found this

information?

2.   Will this enhancement be able to increase the revenue of google adwords by clicking the add on the google Place

page directly and not to any other related site ?

3.   Can ‘Place Page’ really affect the tours n travels guides websites and hence decrease their traffic and business ?

More Articles

Importance of NULL in MYSQL

form_for vs form_tag in Rails