Sha256: d86634f674e98cb84dd9f3c129290a7cdd7dfbfe603860dfd3c493d27553f4e1
Contents?: true
Size: 1.1 KB
Versions: 1
Compression:
Stored size: 1.1 KB
Contents
class PostsController < ApplicationController before_action :set_post, only: %i[show edit update destroy] # 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, status: :unprocessable_entity end end # PATCH/PUT /posts/1 def update if @post.update(post_params) redirect_to @post, notice: "Post was successfully updated." else render :edit, status: :unprocessable_entity 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 list of trusted parameters through. def post_params params.require(:post).permit(:title, :body) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
backy_rb-0.1.3 | dummy/psql/app/controllers/posts_controller.rb |