Sha256: c71244844822247ccdf6256afa4334f9bbff7353ef97a7d332d27144a7da99a0

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

class ArticlesController < ApplicationController
  before_action :set_article, only: [:show, :edit, :update, :destroy]

  # GET /articles
  def index
    @articles = Article.all
  end

  # GET /articles/1
  def show
  end

  # GET /articles/new
  def new
    @article = Article.new
  end

  # GET /articles/1/edit
  def edit
  end

  # POST /articles
  def create
    @article = Article.new(article_params)

    if @article.robot?(params, request.remote_ip)
      redirect_to @article, notice: 'Stupid robot.'
      return
    end

    if @article.save
      redirect_to @article, notice: 'Article was successfully created.'
    else
      render :new
    end
  end

  # PATCH/PUT /articles/1
  def update
    if @article.robot?(params, request.remote_ip)
      redirect_to @article, notice: 'Stupid robot.'
      return
    end
    
    if @article.update(arcticle_params)
      redirect_to @article, notice: 'Article was successfully updated.'
    else
      render :edit
    end
  end

  # DELETE /articles/1
  def destroy
    @article.destroy
    redirect_to articles_url, notice: 'Article was successfully destroyed.'
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_article
      @article = Article.find(params[:id])
    end

    # Only allow a trusted parameter "white list" through.
    def article_params
      params.require(:article).permit(:title, :text)
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
robot_catcher-0.0.1 test/dummy/app/controllers/articles_controller.rb