Sha256: 7eef3f63e6e79e8f1e568dd99265677dda18fdad65e2df5a9b17d56eac282cfc

Contents?: true

Size: 1.01 KB

Versions: 26

Compression:

Stored size: 1.01 KB

Contents

# Used to test #authorize!, #load_and_authorize & load_and_authorize!
class ArticlesController < ApplicationController
  load_and_authorize except: [:index, :show, :new]

  def index
    authorize_and_load_records!
  end

  def show
    load_and_authorize!
  end

  def new
    authorize!
    @article = Article.new
  end

  def edit
  end

  def create
    @article = Article.new(article_params)
    @article.user = current_user
    if @article.save
      redirect_to @article, notice: 'Article was successfully created.'
    else
      render :new
    end
  end

  def update
    @article = Article.find(params[:id])
    if @article.update(article_params)
      redirect_to @article, notice: 'Article was successfully updated.'
    else
      render :edit
    end
  end

  def destroy
    @article = Article.find(params[:id])
    @article.destroy
    redirect_to articles_url, notice: 'Article was successfully destroyed.'
  end

  private

    def article_params
      params.require(:article).permit(:title, :content)
    end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
adeia-0.11.0 spec/test_app/app/controllers/articles_controller.rb
adeia-0.10.5 spec/test_app/app/controllers/articles_controller.rb
adeia-0.10.4 spec/test_app/app/controllers/articles_controller.rb
adeia-0.10.3 spec/test_app/app/controllers/articles_controller.rb
adeia-0.10.2 spec/test_app/app/controllers/articles_controller.rb
adeia-0.10.1 spec/test_app/app/controllers/articles_controller.rb