Sha256: 8bd2ce05c132ff01e96f8f63d8a5e239656e376e965d5addc7aadbd8be986453
Contents?: true
Size: 1.34 KB
Versions: 7
Compression:
Stored size: 1.34 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 @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 redirect_to @article, notice: 'Article was successfully created.' else render :new end end # PATCH/PUT /articles/1 def update if @article.update(article_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.includes(:user).find_by_id(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
7 entries across 7 versions & 1 rubygems