I have 4 sections in the "Page View" section. I work where ALL the contents of each tab are retrieved and displayed when the Event page is requested. It doesn't seem like a good scalability solution ...
How to get content for each tab using AJAX when clicking on a tab?
(The first lesson ... it looks just theoretical, but you can’t get it to work)
I tried adding remote: truetabs to the links, but this does not reflect well on the links on the page - it makes the same receive request Events#Showfor all tabs, which makes it difficult to determine the contents of the tab requested. If I change the href tab to the corresponding links to the controllers, then it breaks the switching of the boot tab. I lose anyway.
Each tab content is divided into separate controllers, so individual content can be selected.
For tab 2, I need to get the content for which I have ever been active nav-pill. And if I'm on Tab # 2, I want to switch its contents from Browse to details and back using links nav-pills.
Using Rails 4 w / bootstrap 3, haml, coffeescript.
Events /show.html.haml
/ Nav tabs
%ul.nav.nav-tabs.color
%li.active
=link_to "Tab1", "#tab1", html_options = { "data-toggle" => "tab" }
%li
=link_to "Tab2", "#tab2", html_options = { "data-toggle" => "tab" }
%li
=link_to "Tab3", "#tab3", html_options = { "data-toggle" => "tab" }
%li
=link_to "Tab4", "#tab4", html_options = { "data-toggle" => "tab" }
/ Tab panes
.tab-content
.tab-pane.active
%p Fetch content
.tab-pane.active
%ul.nav.nav-pills
%li.active= link_to 'Overview', "#overview", html_options = { "data-toggle" => "tab"}
%li= link_to 'Details', "#details", html_options = { "data-toggle" => "tab"}
.tab-content
.tab-pane.active
%p Fetch overview
.tab-pane.active
%p Fetch details
.tab-pane.active
%p Fetch content
.tab-pane.active
%p Fetch content
Controllers / events _controller.rb
def show
respond_to do |format|
format.html
format.js
end
end
views/events/show.js.erb ( remote:true, )
$('div#tab2').append("<%= escape_javascript(render(partial: 'overview', locals: {names: @names, genders: @genders, ages: @ages})) %>")