Sha256: 5ffb83ad07a73069a5c8b8d9a8caabd63368e3b629ea2c437a4d0eb67679632c

Contents?: true

Size: 1.57 KB

Versions: 20

Compression:

Stored size: 1.57 KB

Contents

class PostsController < ApplicationController
  before_action :set_post, only: %i[ show edit update destroy ]

  def index
    @posts = Post.all
  end

  # Dangerous Evaluation - User input in an eval statement is VERY dangerous
  def show
    message = params[:message] || 'hello world'

    eval("echo '#{message}'")
  end

  def new
    @post = Post.new
  end

  def edit
  end

  def create
    @post = Post.new(post_params)

    respond_to do |format|
      if @post.save
        format.html { redirect_to post_url(@post), notice: "Post was successfully created." }
        format.json { render :show, status: :created, location: @post }
      else
        format.html { render :new, status: :unprocessable_entity }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

  def update
    respond_to do |format|
      if @post.update(post_params)
        format.html { redirect_to post_url(@post), notice: "Post was successfully updated." }
        format.json { render :show, status: :ok, location: @post }
      else
        format.html { render :edit, status: :unprocessable_entity }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

  def destroy
    @post.destroy

    respond_to do |format|
      format.html { redirect_to posts_url, notice: "Post was successfully destroyed." }
      format.json { head :no_content }
    end
  end

  private
    def set_post
      @post = Post.find(params[:id])
    end

    def post_params
      params.require(:post).permit(:title, :body)
    end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
rails_app_generator-0.3.6 after_templates/addons/brakeman/app/controllers/posts_controller.rb
rails_app_generator-0.3.5 after_templates/addons/brakeman/app/controllers/posts_controller.rb
rails_app_generator-0.3.4 after_templates/addons/brakeman/app/controllers/posts_controller.rb
rails_app_generator-0.3.3 after_templates/addons/brakeman/app/controllers/posts_controller.rb
rails_app_generator-0.3.2 after_templates/addons/brakeman/app/controllers/posts_controller.rb
rails_app_generator-0.3.1 after_templates/addons/brakeman/app/controllers/posts_controller.rb
rails_app_generator-0.3.0 after_templates/addons/brakeman/app/controllers/posts_controller.rb
rails_app_generator-0.2.43 after_templates/addons/brakeman/app/controllers/posts_controller.rb
rails_app_generator-0.2.42 after_templates/addons/brakeman/app/controllers/posts_controller.rb
rails_app_generator-0.2.41 after_templates/addons/brakeman/app/controllers/posts_controller.rb
rails_app_generator-0.2.40 after_templates/addons/brakeman/app/controllers/posts_controller.rb
rails_app_generator-0.2.39 after_templates/addons/brakeman/app/controllers/posts_controller.rb
rails_app_generator-0.2.38 after_templates/addons/brakeman/app/controllers/posts_controller.rb
rails_app_generator-0.2.37 after_templates/addons/brakeman/app/controllers/posts_controller.rb
rails_app_generator-0.2.36 after_templates/addons/brakeman/app/controllers/posts_controller.rb
rails_app_generator-0.2.35 after_templates/addons/brakeman/app/controllers/posts_controller.rb
rails_app_generator-0.2.34 after_templates/addons/brakeman/app/controllers/posts_controller.rb
rails_app_generator-0.2.33 after_templates/addons/brakeman/app/controllers/posts_controller.rb
rails_app_generator-0.2.32 after_templates/addons/brakeman/app/controllers/posts_controller.rb
rails_app_generator-0.2.31 after_templates/addons/brakeman/app/controllers/posts_controller.rb