Sha256: 25abf73a3516ef43254fe412d14e60978683123c4f4bdbbb32a6116d3883fd1a

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

class SelectionsController < ApplicationController
  before_action :parent_finder

  def index
    if @parent
      @selections = @parent.children
    else
      @selections = Selection.roots
    end
  end

  def new
    @selection = @parent.children.new
  end

  def edit
    @selection = @parent.children.find(params[:id])
  end

  def create
    @selection = @parent.children.new(params[:selection])

    if @selection.save
      redirect_to selection_selections_path(@parent), notice: 'Selection was successfully created.'
    else
      render action: 'new'
    end
  end

  def update
    @selection = Selection.find(params[:id])

    if @selection.update_attributes(params[:selection])
      redirect_to selection_selections_path(@parent), notice: 'Selection was successfully updated.'
    else
      render action: 'edit'
    end
  end

  def destroy
    @selection = Selection.find(params[:id])
    @selection.destroy

    redirect_to selections_url
  end

  private

  def parent_finder
    @parent = Selection.find_by_id(params[:selection_id])
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
selections-1.1.1 lib/generators/selections_scaffold/templates/selections_controller.rb
selections-1.0.5 lib/generators/selections_scaffold/templates/selections_controller.rb
selections-1.0.4 lib/generators/selections_scaffold/templates/selections_controller.rb
selections-1.1.0 lib/generators/selections_scaffold/templates/selections_controller.rb
selections-1.0.3 lib/generators/selections_scaffold/templates/selections_controller.rb