Sha256: 24f12874d872a2c0572167a69bb6b8a514cc44bf06358e5f1738b2e68ed7c3df

Contents?: true

Size: 1.36 KB

Versions: 3

Compression:

Stored size: 1.36 KB

Contents

require_dependency "ucpengine/application_controller"

module Ucpengine
  class EntriesController < ApplicationController
    before_action :set_entry, only: [:show, :edit, :update, :destroy]

   def index
     @entries = Entry.where(type: content_class)
   end

   def show
   end

   def new
     @entry = Entry.new(type: content_class)
   end

   def edit
   end

   def create
     @entry = Entry.new(entry_params)

     if @entry.save
       #redirect_to content_entry_path(@entry), notice: 'Entry was successfully created.'
       redirect_to content_entries_path, notice: 'Entry was successfully created.'
     else
       render :new
     end
   end

   def update
     if @entry.update(entry_params)
       redirect_to content_entry_path(@entry), notice: 'Entry was successfully updated.'
     else
       render :edit
     end
   end

   def destroy
     @entry.destroy
     redirect_to content_entries_path, notice: 'Entry was successfully destroyed.'
   end

   private

   def set_entry
     @entry = Entry.find(params[:id])
   end

   def entry_params
     allowed_attrs = %i(id type termsofservice version slug published_at)
       .concat(content_class.constantize.content_attributes.keys)

     params.require(:entry).permit(*allowed_attrs)
   end

   def content_class
     @content_class ||= params[:content_class].classify
   end
   helper_method :content_class
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ucpengine-0.0.6 app/controllers/ucpengine/entries_controller.rb
ucpengine-0.0.5 app/controllers/ucpengine/entries_controller.rb
ucpengine-0.0.4 app/controllers/ucpengine/entries_controller.rb