The example code can be fetched from here:
http://github.com/tsenying/rails_jquery_ajax_tabs
Steps:
1. Create the Rails app, use the -d option to set the database adaptor.
rails -d postgresql rails_jquery_ajax_tabs2. Setup controller and views to be tabbed.
script/generate controller about tab1 tab2 tab3 tab43. Download and add jquery.js, jquery-ui.js to the rails app directory public/javascripts and jquery-ui stylesheet to public/stylesheets,
from http://jqueryui.com/download
4. Create layout with jquery javascript files and stylesheet.
- add jquery stylesheet to layout
<%= stylesheet_link_tag "jquery-ui-1.7.2.custom", :cache => true %>
- add jquery javascript files to layout (both core and ui) and also application.js
<%= javascript_include_tag "jquery-1.3.2.min", "jquery-ui-1.7.2.custom.min", "application" %>
5. setup up tabs markup in layout,
match the link 'title' attribute and the content container's id, otherwise jquery dynamically creates the container.
Using links pointing to the server instead of named anchors inside the same document causes jquery ui tabs to ajaxify the tabs behavior.
<div id="tabs">
<ul>
<li><%= link_to content_tag(:span, "Tab1"),
{:controller => "about", :action => "tab1"},
{:title => "main_content"} %></li>
<li><%= link_to content_tag(:span, "Tab2"),
{:controller => "about", :action => "tab2"},
{:title => "main_content"} %></li>
<li><%= link_to content_tag(:span, "Tab3"),
{:controller => "about", :action => "tab3"},
{:title => "main_content"} %></li>
</ul>
</div>
<div id="main_content">
<%= yield %>
</div>
6. Create jquery tabs in application.js
$(document).ready(function(){
$("#tabs").tabs();
});
7. create tab content views in views/about/ e.g. tab1.html.erb :
<h1>About#tab1</h1>
<p>Find me in app/views/about/tab1.html.erb</p>
8. turn off layout in controller if request.xhr?
layout :determined_by_request
protected
def determined_by_request
if request.xhr?
return false
else
'application'
end
end
9. set up routes in config/routes.rb:
map.root :controller => "about", :action => "tab1"
References:
http://docs.jquery.com/UI/Tabs
http://jqueryui.com/demos/tabs/
Similar implementation using prototype: http://www.eduvoyage.com/2008/9/26/ajax-tabs-and-rails and http://www.eduvoyage.com/2009/3/14/ajax-tabs-and-rails-2
Hi, can you explain the steps to clone the project for rails tab and lauch via rails . I get the error gemfile not found.
ReplyDeleteThanks,
Srugby
Digital Marketing, Web Design training provided by 100% real-time practical Training with real-time working professional which will help students and trainees to get trained in practical real-time scenarios along with theory. Best Web Design Training
ReplyDeleteThanks for sharing this blog. This very important and informative blog
ReplyDeletesap mm training in bangalore
sap mm courses in bangalore
sap mm classes in bangalore
sap mm training institute in bangalore
sap mm course syllabus
best sap mm training
sap mm training centers
The Blog is really very Impressive.every content should be very neatly represented.
ReplyDeleteData Science Training Course In Chennai | Data Science Training Course In Anna Nagar | Data Science Training Course In OMR | Data Science Training Course In Porur | Data Science Training Course In Tambaram | Data Science Training Course In Velachery
Very interesting blog Thank you for sharing such a nice and interesting blog and really very helpful article.I have recently visited your blog profile. I am totally impressed by your blogging skills and knowledge
ReplyDeleteData Science Training In Chennai
Data Science Online Training In Chennai
Data Science Training In Bangalore
Data Science Training In Hyderabad
Data Science Training In Coimbatore
Data Science Training
Data Science Online Training
Great content thanks for sharing this informative blog which provided me technical information keep posting.thanks lot!!
ReplyDeleteandroid training in chennai
android online training in chennai
android training in bangalore
android training in hyderabad
android Training in coimbatore
android training
android online training
I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.
ReplyDeletedata science interview questions
Thanks for a marvelous posting! I seriously enjoyed reading it, you are
ReplyDeletea great author.I will be sure to bookmark your blog and will often come back in the future.
I want to encourage yourself to continue your great job, have a
nice weekend!
java training in chennai
java training in velachery
aws training in chennai
aws training in velachery
python training in chennai
python training in velachery
selenium training in chennai
selenium training in velachery
Such a helpful article. Interesting to peruse this article.I might want to thank you for the endeavors you had made for composing this wonderful article.
ReplyDeletedata scientist training and placement in hyderabad
Nice blog, very informative content.Thanks for sharing, waiting for the next update…
ReplyDeleteFeatures of Java Programming Language
Features of Java
very intersting to read your blog and it makes the viewers to visit your blog and keep on updating.
ReplyDeleteTally Training in Bangalore
Tally Course in Hyderabad
It was a wonderful chance to visit this kind of site and I am happy to know. Thank you so much for giving us a chance to have this opportunity..
ReplyDeletedata scientist training in hyderabad
Explore what the best Data Science training institute is offering you. Learn advanced technologies from the best industry experts and grab lucrative jobs.
ReplyDeletedata analytics courses in hyderabad with placements