Skip to content

Instantly share code, notes, and snippets.

@cmeiklejohn
Forked from buethling/microposts
Created March 8, 2011 03:02
Show Gist options
  • Save cmeiklejohn/859778 to your computer and use it in GitHub Desktop.
Save cmeiklejohn/859778 to your computer and use it in GitHub Desktop.
class MicropostsController < ApplicationController
before_filter :set_micropost, :only => [:show, :edit, :update, :create, :new]
before_filter :authenticate, :only => [:create, :destroy] # Same here?
# Omitted.
def destroy
@micropost.destroy
redirect_back_or root_path
end
def set_micropost
# If this record can't be found, it will throw ActiveRecord::RecordNotFound,
# which will cause rails to return a 404.
# Now you don't need to check if the owner is the user, since we infer that here.
@micropost = current_user.microposts.find(params[:id])
end
private :set_micropost
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment