Sha256: 996bb6e6309bd83b45f17ae248f82d1a9da020c5220af1c1fa1c5675fa878589

Contents?: true

Size: 987 Bytes

Versions: 4

Compression:

Stored size: 987 Bytes

Contents

class TreesController < ApplicationController
  before_action :set_tree, only: [:show, :edit, :update, :destroy]

  def index
    @trees = Tree.all
    @data = Lasha.index_data(
      controller: self,
      collection: Tree.all.order(created_at: :desc).limit(20),
      attributes: %i[title]
    )
  end

  def show
  end

  def new
    @tree = Tree.new
  end

  def edit
  end

  def create
    @tree = Tree.new(tree_params)

    if @tree.save
      redirect_to @tree, notice: 'Tree was successfully created.'
    else
      render :new
    end
  end

  def update
    if @tree.update(tree_params)
      redirect_to @tree, notice: 'Tree was successfully updated.'
    else
      render :edit
    end
  end

  def destroy
    @tree.destroy
    redirect_to trees_url, notice: 'Tree was successfully destroyed.'
  end

  private

    def set_tree
      @tree = Tree.find(params[:id])
    end

    def tree_params
      params.require(:tree).permit(:title, :content, :toggler)
    end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lasha-0.4.2 spec/dummy/app/controllers/trees_controller.rb
lasha-0.4.1 spec/dummy/app/controllers/trees_controller.rb
lasha-0.4.0 spec/dummy/app/controllers/trees_controller.rb
lasha-0.3.4 spec/dummy/app/controllers/trees_controller.rb