public
Last active

Rendering partials within nested tabs

  • Download Gist
_lesson_content.html.haml
Haml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
.tab-content
- @course.lessons.each_with_index do |lesson, index|
%div{:class => "tab-pane #{'active' if index == 0}", :id => "lesson_#{lesson.id}"}
.page-header
%h2{:class => 'inline'}
Lesson:
= raw lesson.lesson_name
%small{:class => 'btn-group', :style => "float:right"}
= link_to("#", :class => "btn-large btn-info prevtab") do
<i class="icon-chevron-left icon-white"></i> Back
&nbsp;
= link_to("#", :class => "btn-large btn-success nexttab") do
Next <i class="icon-chevron-right icon-white"></i>
&nbsp;
= edit_lesson_link(@course, lesson)
 
- if enrolled
%p= lesson.lesson_overview.gsub(/\n/, '<br/>').html_safe
- else
%p= raw "#{lesson.lesson_overview[0..200]}..."
- if lesson.youtube_id
%center= raw "#{lesson.youtube_id}"
 
- if lesson.vimeo_id
- if enrolled
- if lesson.vimeo_id
%center= raw lesson.get_from_vimeo
.page-header
%h2 Lesson exercises
- if enrolled
%p= raw lesson.lesson_practical.gsub(/\n/, '<br/>').html_safe
- else
%p= raw "#{lesson.lesson_practical[0..200]}..."
_show_header.html.erb
HTML+ERB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
<div class='row'>
<div class='span2'>
<%= image_tag @course.image.url(:thumb) %>
</div>
<div class='span7'>
<h2><%= @course.course_name %>&nbsp;<%= link_to "Edit Course", edit_course_path(@course), :class => 'btn btn-info' if current_user == @course.publisher %></h2><br />
<h2 class='inline'><%= @course.category.name %> | Level <%= @course.level_id %></h2>
</div>
<div class='span3'>
<div class='well'>
<br />
<div class='btn-group' align='center'>
<%= link_to new_enrolment_path(:course_id => @course.id), :class => 'btn btn-large btn-success span2', :method => "get" do %>
ENROLL FOR <%= humanized_money_with_symbol @course.price %>
<% end %>
</div>
<br />
</div>
</div>
</div>
 
<div class='row'>
<div class='span9'>
<br />
<div class='tabbable'>
<ul class='nav nav-tabs' id='myTabs'>
<li><a href="#a1" data-toggle="tab">Overview</a></li>
<li><a href="#a2" data-toggle="tab">Expected Results</a></li>
<li><a href="#a3" data-toggle="tab">Coach Bio</a></li>
<li><a href="#a4" data-toggle="tab">Lessons</a></li>
<li class='inline' style='float:right'><%= render :partial => 'shared/facebook' %></li>
</ul>
</div>
</div>
</div>
 
 
 
 
 
courses.js.coffee
CoffeeScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
$(document).ready ->
$('#lesson_tabs').hide()
$('#lesson_tabs a:first').tab('show')
$(".nexttab").click (evt) ->
$active_tab = $(".active")
$active_tab.next().children("a").trigger "click" if $active_tab.next().length > 0
evt.preventDefault();
$(".prevtab").click (evt) ->
$active_tab = $(".active")
$active_tab.prev().children("a").trigger "click" if $active_tab.prev().length > 0
evt.preventDefault();
$('a[data-toggle="tab"]:first').tab('show');
show.html.erb
HTML+ERB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
<input id="logged_in" type="hidden" value="<%= !current_user.nil? %>">
 
<div class="row">
<div class="span12">
<%= render :partial => 'show_header' %>
</div>
<div class='span9'>
<div class='tab-content'>
<div class="tab-pane" id="a1">
<h2>Course description</h2><br />
<p><%= @course.course_overview %></p>
</div>
 
<div class="tab-pane" id="a2">
<h2>What you can expect from the course</h2><br />
<p><%= @course.expected_results %></p>
</div>
 
<div class="tab-pane" id="a3">
<h2>Course tutor profile</h2><br />
<p><%= @course.tutor_bio %></p>
</div>
<div class="tab-pane" id="a4">
<%= render :partial => 'lesson_tabs' %>
<%= render :partial => 'lesson_content', :locals => {:enrolled => false} %>
</div>
</div>
</div>
 
<script>
window.course_id = <%= @course.id if @course %>;
</script>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.