Skip to content

Commit

Permalink
Refactors the PlantsController
Browse files Browse the repository at this point in the history
Refactors the PlantsController, adding the #plant & #plants methods.
  • Loading branch information
rringler committed Dec 25, 2015
1 parent fcfebea commit 4ba1948
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions app/controllers/plants_controller.rb
Expand Up @@ -19,19 +19,19 @@ def create
end

def index
@plants = Plant.all.decorate
@plants = plants
end

def show
@plant = Plant.where(id: params[:id]).first.decorate
@plant = plant
end

def edit
@plant = Plant.where(id: params[:id]).first
@plant = plant
end

def update
@plant = Plant.where(id: params[:id]).first
@plant = plant

if @plant.update_attributes(plant_params)
redirect_to @plant, flash: { success: "Plant updated." }
Expand All @@ -41,19 +41,28 @@ def update
end

def destroy
@plant = Plant.where(id: params[:id]).first
@plant = plant
@plant.destroy

redirect_to root_path
end

private

def plant
@plant ||= Plant.find(params[:id])
end

def plants
@plants ||= Plant.all.decorate
end

def plant_params
params.require(:plant).permit(:name,
:signal_power_pin,
:signal_channel,
:pump_power_pin,
:moisture_threshold)
params.require(:plant)
.permit(:name,
:signal_power_pin,
:signal_channel,
:pump_power_pin,
:moisture_threshold)
end
end

0 comments on commit 4ba1948

Please sign in to comment.