Sha256: eb466cf80b091b987cb834e8b42207eb5f6da7667e3ad4d3b19f548b44143316

Contents?: true

Size: 1.71 KB

Versions: 14

Compression:

Stored size: 1.71 KB

Contents

class ArticlesController < ApplicationController
  before_action :authenticate_user!, except: [:index, :show]
  before_action :set_article, only: [:show, :edit, :update, :destroy]

  # GET /articles
  def index
    @exists_notifications_routes       = respond_to?('notifications_path')
    @exists_user_notifications_routes  = respond_to?('user_notifications_path')
    @exists_admins_notifications_routes = respond_to?('admins_notifications_path')
    @exists_admin_notifications_routes = respond_to?('admin_notifications_path')
    @articles = Article.all.includes(:user)
  end

  # GET /articles/1
  def show
    @comment = Comment.new
  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)
    @article.user = current_user

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

  # PATCH/PUT /articles/1
  def update
    if @article.update(article_params)
      @article.notify :users, key: 'article.update'
      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.includes(:user).find(params[:id])
    end

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
activity_notification-2.3.3 spec/rails_app/app/controllers/articles_controller.rb
activity_notification-2.3.2 spec/rails_app/app/controllers/articles_controller.rb
activity_notification-2.3.1 spec/rails_app/app/controllers/articles_controller.rb
activity_notification-2.3.0 spec/rails_app/app/controllers/articles_controller.rb
activity_notification-2.2.4 spec/rails_app/app/controllers/articles_controller.rb
activity_notification-2.2.3 spec/rails_app/app/controllers/articles_controller.rb
activity_notification-2.2.2 spec/rails_app/app/controllers/articles_controller.rb
activity_notification-2.2.1 spec/rails_app/app/controllers/articles_controller.rb
activity_notification-2.2.0 spec/rails_app/app/controllers/articles_controller.rb
activity_notification-2.1.4 spec/rails_app/app/controllers/articles_controller.rb
activity_notification-2.1.3 spec/rails_app/app/controllers/articles_controller.rb
activity_notification-2.1.2 spec/rails_app/app/controllers/articles_controller.rb
activity_notification-2.1.1 spec/rails_app/app/controllers/articles_controller.rb
activity_notification-2.1.0 spec/rails_app/app/controllers/articles_controller.rb