Title / Description
Code class MicropostsController < ApplicationController before_filter :authenticate, :only => [:create, :destroy] before_filter :authorized_user, :only => :destroy def create @micropost = current_user.microposts.build(params[:micropost]) if @micropost.save flash[:success] = "Micropost created!" redirect_to root_path else @feed_items = [] render 'pages/home' end end def destroy if @micropost.destroy flash[:success] = "Micropost destroyed!" else flash[:error] = "Error on micropost destroyed!" end redirect_back_or root_path end private def authorized_user @micropost = Micropost.find(params[:id]) redirect_to root_path unless current_user?(@micropost.user) end end
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code