Sha256: ba0a7e0295a016f393d2b6f2ab308d9bf3a530fab0203acd0e8cede44f2cb74a
Contents?: true
Size: 1.31 KB
Versions: 2
Compression:
Stored size: 1.31 KB
Contents
class PostsController < ApplicationController theme :theme_resolver, except: [:new] if Rails::VERSION::MAJOR == 4 before_action :set_post, only: [:show, :edit, :update, :destroy] else before_filter :set_post, only: [:show, :edit, :update, :destroy] end # 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 action: 'new' end end # PATCH/PUT /posts/1 def update if @post.update(post_params) redirect_to @post, notice: 'Post was successfully updated.' else render action: '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(:title, :description) end def theme_resolver params[:theme].presence || "theme_a" end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
themes_on_rails-0.3.1 | spec/dummy/app/controllers/posts_controller.rb |
themes_on_rails-0.3.0 | spec/dummy/app/controllers/posts_controller.rb |