Class: GnarusExercise::ExercisesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- GnarusExercise::ExercisesController
- Defined in:
- app/controllers/gnarus_exercise/exercises_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
-
#destroy ⇒ Object
DELETE /exercises/1 DELETE /exercises/1.json.
-
#edit ⇒ Object
GET /exercises/1/edit.
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/gnarus_exercise/exercises_controller.rb', line 23 def create @exercise = Exercise.new(params[:exercise]) @exercise. = current_user if defined?(Devise) if @exercise.save redirect_to @exercise, notice: 'Exercise was successfully created.' else render action: "new" end end |
#destroy ⇒ Object
DELETE /exercises/1 DELETE /exercises/1.json
46 47 48 49 50 51 52 53 |
# File 'app/controllers/gnarus_exercise/exercises_controller.rb', line 46 def destroy @exercise = Exercise.find(params[:id]) if defined?(Devise) && @exercise. == current_user @exercise.destroy end redirect_to exercises_url end |
#edit ⇒ Object
GET /exercises/1/edit
19 20 21 |
# File 'app/controllers/gnarus_exercise/exercises_controller.rb', line 19 def edit @exercise = Exercise.find(params[:id]) end |
#index ⇒ Object
6 7 8 |
# File 'app/controllers/gnarus_exercise/exercises_controller.rb', line 6 def index @exercises = Exercise.all.select{|e| e..id == current_user.id} end |
#new ⇒ Object
14 15 16 |
# File 'app/controllers/gnarus_exercise/exercises_controller.rb', line 14 def new @exercise = Exercise.new end |
#show ⇒ Object
10 11 12 |
# File 'app/controllers/gnarus_exercise/exercises_controller.rb', line 10 def show @exercise = Exercise.find(params[:id]) end |
#update ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/gnarus_exercise/exercises_controller.rb', line 34 def update @exercise = Exercise.find(params[:id]) if defined?(Devise) && @exercise. == current_user params[:exercise].delete :author_id @exercise.update_attributes(params[:exercise]) end redirect_to @exercise, notice: 'Exercise was successfully updated.' end |