-
-
Save cmeiklejohn/859778 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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