Commit 75ca729

mo khan <mo@mokhan.ca>
2016-05-28 16:41:24
extract each_exercise method.
1 parent 5375873
Changed files (2)
app
models
views
app/models/program.rb
@@ -2,21 +2,23 @@ class Program < ActiveRecord::Base
   STRONG_LIFTS = "StrongLifts 5×5"
   has_many :exercises, through: :workouts
   has_many :workouts
-  before_save :save_slug
+  before_save do
+    self.slug = name.parameterize
+  end
 
   def to_param
     slug
   end
 
+  def each_exercise
+    exercises.uniq.each do |exercise|
+      yield exercise
+    end
+  end
+
   class << self
     def stronglifts
       Program.find_by(name: STRONG_LIFTS)
     end
   end
-
-  private
-
-  def save_slug
-    self.slug = name.parameterize
-  end
 end
app/views/profiles/show.html.erb
@@ -25,7 +25,7 @@
         </tr>
       </thead>
       <tbody>
-        <% @program.exercises.uniq.each do |exercise| %>
+        <% @program.each_exercise do |exercise| %>
           <tr>
             <td> <strong><%= exercise.name %></strong></td><td><%= @user.personal_record_for(exercise) %> lbs</td>
           </tr>
@@ -37,7 +37,7 @@
 
 <div>
   <div class="small-12 columns small-text-center medium-text-left">
-    <% @program.exercises.uniq.each do |exercise| %>
+    <% @program.each_exercise do |exercise| %>
       <%= render @user.history_for(exercise) %>
     <% end %>
   </div>