Sha256: 6595b197ca51dc92b57bca0b0c4675df5bf1467e4b8fe40ff6ae4d177b51276b

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

class PostsController < ApplicationController
  before_action :set_post, only: [:show, :edit, :update, :destroy]
  metaslug_vars :post, only: :show
  metaslug_vars :post, only: :edit

  # GET /posts
  def index
    @posts = Post.all
  end

  # GET /posts/1
  def show
  end

  # GET /posts/new
  def new
    @post = Post.new
  end

  # GET /posts/1/edit
  def edit
  end

  # POST /posts
  def create
    @post = Post.new(post_params)

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

  # PATCH/PUT /posts/1
  def update
    if @post.update(post_params)
      redirect_to @post, notice: 'Post was successfully updated.'
    else
      render :edit
    end
  end

  # DELETE /posts/1
  def destroy
    @post.destroy
    redirect_to posts_url, notice: 'Post was successfully destroyed.'
  end

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

    # Only allow a trusted parameter "white list" through.
    def post_params
      params.require(:post).permit(:content, :title, :active, :category_id)
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
metaslug-0.3.5 test/dummy/app/controllers/posts_controller.rb
metaslug-0.3.4 test/dummy/app/controllers/posts_controller.rb
metaslug-0.3.3 test/dummy/app/controllers/posts_controller.rb