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