Skip to content

Commit

Permalink
rails nested url for reps resource, controller, view
Browse files Browse the repository at this point in the history
  • Loading branch information
Oladele committed Apr 29, 2014
1 parent 75af1b2 commit 120ac04
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
18 changes: 18 additions & 0 deletions app/controllers/reps_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class RepsController < ApplicationController
respond_to :json

def index
# sleep 5
# @reps = Rep.all
sett = Sett.find(params[:sett_id])
@reps = sett.reps
@exercises = Exercise.all
end

private

def rep_params
params.require(:rep).permit(:sett_id, :position)
end

end
5 changes: 5 additions & 0 deletions app/views/reps/_base.json.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
attributes :id, :sett_id, :exercise_id, :resistance, :position

node(:exercise_name)do |rep|
@exercises.find(rep.exercise_id).name
end
3 changes: 3 additions & 0 deletions app/views/reps/index.json.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
collection @reps

extends "reps/_base"
5 changes: 4 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
resources :setts
end

resources :setts
resources :setts do
resources :reps
end

resources :leads, :only => [:index]

root to: "application#index"
Expand Down

0 comments on commit 120ac04

Please sign in to comment.