I have a nav-tab in my users show-view.
I want to render partial in each tab, I haven't got it to work yet, I have spent all day on figuring this out. I have checked lots of post on stackowerflow and I've googled allot but I can never managed to make each tab show each partial.
I´m really new to coding but I´m learning by doing, so I know it can be a struggle.
My code as it is now is below, it is basically a copy from this post Rails 3/jquery - Tabs rendering partials using ajax
Can anyone take a look at this and help me, I´m really out of options here and very frustrated
thanks in advance Dadi
in my users/show.rb
<div class="container">
<ul class="nav nav-tabs">
<li class="active"><%= link_to "Pappír", {:controller => "users", :action => "tab"}, :remote => true %></li>
<li data-toggle="tab" ><%= link_to "Rafmagn", {:controller => "users", :action => "tab"}, :remote => true %></li>
<li data-toggle="tab" ><%= link_to "Vatn", {:controller => "users", :action => "tab"}, :remote => true %></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane" id="pappir">
<%= render 'pages/partials/paper_part' %>
</div>
<div role="tabpanel" class="tab-pane" id="rafmagn">
<%= render 'pages/partials/electro_part' %>
</div>
<div role="tabpanel" class="tab-pane" id="hwater">
<%= render 'pages/partials/hwater_part' %>
</div>
I did this method in my users_controller.rb
def tab
respond_to do |format|
format.js
end
end
in view/users/tab.js.erb
$('#pappir').html("<%= escape_javascript(render('pages/partials/paper_part')) %>");
$('#rafmagn').html("<%= escape_javascript(render('pages/partials/electro_part')) %>");
$('#hwater').html("<%= escape_javascript(render('pages/partials/hwater_part')) %>");
in my routes.rb
resources :users, only: [:show] do
member do
get 'tab'
end
end