Skip to content

Instantly share code, notes, and snippets.

@abriening
Created August 24, 2013 21:28
Show Gist options
  • Save abriening/6330507 to your computer and use it in GitHub Desktop.
Save abriening/6330507 to your computer and use it in GitHub Desktop.
How pretty the Rails 3 controllers can be.
class GoalsController < ApplicationController
respond_to :html, :json
before_action :set_goal, only: [:show, :edit, :update]
def show
respond_with @goal
end
def edit
respond_with @goal
end
def update
if @goal.update(goal_params)
flash[:notice] = 'Goal was successfully updated.'
end
respond_with @goal
end
private
def set_goal
@goal = Goal.find(params[:id])
end
def goal_params
params.require(:goal).permit(:name, :description, :goal_type)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment