33 lines
852 B
Ruby
33 lines
852 B
Ruby
class MicropostsController < ApplicationController
|
|
before_action :set_micropost, only: %i[ show edit update destroy ]
|
|
def create
|
|
@micropost = current_user.microposts.build(micropost_params)
|
|
authorize @micropost
|
|
if @micropost.save
|
|
flash[:success] = "Micropost created!"
|
|
redirect_to root_url
|
|
else
|
|
render 'users/show'
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
authorize @micropost
|
|
@micropost.destroy
|
|
respond_to do |format|
|
|
format.html { redirect_to request.referrer || root_url, notice: "Post was deleted." }
|
|
format.json { head :no_content }
|
|
end
|
|
end
|
|
|
|
private
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
def set_micropost
|
|
@micropost = Micropost.find(params[:id])
|
|
end
|
|
|
|
def micropost_params
|
|
params.require(:micropost).permit(:content)
|
|
end
|
|
end
|