class MicropostsController

Public Instance Methods

create() click to toggle source
# File lib/generators/chapter11_3/solutions/templates/app/controllers/microposts_controller.rb, line 4
def create
  @micropost  = current_user.microposts.build(params[:micropost])
  if @micropost.save
    flash[:success] = "Micropost created!"
    redirect_to root_path
  else
    render 'pages/home'
  end
end
destroy() click to toggle source
# File lib/generators/chapter11_3/solutions/templates/app/controllers/microposts_controller.rb, line 14
def destroy
  # .try will call the method given, unless the caller is nil
  current_user.microposts.find_by_id(params[:id]).try(:destroy)
  redirect_to :back
end