Sha256: 5bb74c46f7487e2837fb16069ac2471698dd0fc21e7c8f84a23ea6431d11468d

Contents?: true

Size: 723 Bytes

Versions: 20

Compression:

Stored size: 723 Bytes

Contents

class MicropostsController < ApplicationController
  before_action :signed_in_user, only: [:create, :destroy]
  before_action :correct_user,   only: :destroy

  def create
    @micropost = current_user.microposts.build(micropost_params)
    if @micropost.save
      flash[:success] = "Micropost created!"
      redirect_to root_url
    else
      @feed_items = []
      render 'static_pages/home'
    end
  end

  def destroy
    @micropost.destroy
    redirect_to root_url
  end

  private

    def micropost_params
      params.require(:micropost).permit(:content)
    end

    def correct_user
      @micropost = current_user.microposts.find_by(id: params[:id])
      redirect_to root_url if @micropost.nil?
    end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
rails_magic_renamer-2.0.0.pre.alpha spec/support/sample_app_rails_4/app/controllers/microposts_controller.rb
active_mocker-1.4.2 sample_app_rails_4/app/controllers/microposts_controller.rb
active_mocker-1.4.1 sample_app_rails_4/app/controllers/microposts_controller.rb
active_mocker-1.3.2 sample_app_rails_4/app/controllers/microposts_controller.rb
active_mocker-1.3.1 sample_app_rails_4/app/controllers/microposts_controller.rb
active_mocker-1.3 sample_app_rails_4/app/controllers/microposts_controller.rb
active_mocker-1.2.4 sample_app_rails_4/app/controllers/microposts_controller.rb
active_mocker-1.2.3 sample_app_rails_4/app/controllers/microposts_controller.rb
active_mocker-1.2 sample_app_rails_4/app/controllers/microposts_controller.rb
active_mocker-1.2.pre.11 sample_app_rails_4/app/controllers/microposts_controller.rb
active_mocker-1.2.pre.10 sample_app_rails_4/app/controllers/microposts_controller.rb
active_mocker-1.2.pre.9 sample_app_rails_4/app/controllers/microposts_controller.rb
active_mocker-1.2.pre.8 sample_app_rails_4/app/controllers/microposts_controller.rb
active_mocker-1.2.pre.7 sample_app_rails_4/app/controllers/microposts_controller.rb
active_mocker-1.2.pre.6 sample_app_rails_4/app/controllers/microposts_controller.rb
active_mocker-1.2.pre.5 sample_app_rails_4/app/controllers/microposts_controller.rb
active_mocker-1.2.pre.4 sample_app_rails_4/app/controllers/microposts_controller.rb
active_mocker-1.2.pre.3 sample_app_rails_4/app/controllers/microposts_controller.rb
active_mocker-1.2.pre.2 sample_app_rails_4/app/controllers/microposts_controller.rb
active_mocker-1.2.pre.1 sample_app_rails_4/app/controllers/microposts_controller.rb