Fbtt Facebooker Tutorial

Next Lesson → Invite Friends

2.1) Tabs


This lesson shows you how to render a facebook tab control.

FBML tab control is handled by two methods, fb_tabs and fb_tab_item. If you check out the wiki you will see that fb_tabs tag contains some number of fb_tab_item tags. Here is how the tab control is created for this tutorial.

  1. Create a method to determine if the current tab is selected or not.
    1
    2
    3
    4
    
    #File: app/helpers/application_helper.rb Method: tab_selected?
    def tab_selected?(section)
       (section.lessons.first.url_options[:controller] == params[:controller])
    end
    
  2. Now create the fb_tabs container and all the fb_tab_items
    1
    2
    3
    4
    5
    
    # File: app/views/layouts/_section_tabs.rhtml
            
        <% fb_tabs do %>  
               <%= section_tab_items() %>  
        <% end %>      
    1
    2
    3
    4
    5
    6
    
    #File: app/helpers/application_helper.rb Method: section_tab_items
    def section_tab_items
       LessonOutline.outline.sections.collect do |section|
          fb_tab_item(section.name, url_for(section.lessons.first.url_options), :selected => tab_selected?(section) )
       end.join("\n")
    end
    
    Note: fb_tabs method is a little touchy on what the block that you pass it does. The is why I factored out the code that returns the tab_items.
Next Lesson → Invite Friends
Peepcodead
Comment Section for Tabs
Displaying all 7 posts.

Evan wroteat 3:11pm on September 10th, 2008

I approached this slightly differently using the url_for as the core of my tab_selected? method and compared it to the current url, perhaps not the cleanest but just another option.

David wroteat 2:01pm on March 6th, 2008

Forms is on my list of things to do. There are some decent examples in the facebooker docs I think.

Zia wroteat 7:25pm on March 5th, 2008

Any idea when can we have a look at the source code. Right now, I'm stuck at handling fbml forms request.

Jorge wroteat 8:53am on February 28th, 2008

Yeah, a download of the source would be the most helpful I think. That way people could ask deeper questions that just ask about simple logistics. Thanks.

David wroteat 8:17pm on February 27th, 2008

LessonOutline is a class that is used just in this tutorial. You can put anything you want in there. I think I need to make those things more clear. Or provide the Tutorial Source to download.

Jorge wroteat 10:57am on February 27th, 2008

What subclass does 'LessonOutline' inherit from? Where should I put it?

David wroteat 4:33pm on February 18th, 2008

ok