Sha256: 843637b01badc2c7cecf64576fab525371f72311697b388ce7ffd02eccde0af6

Contents?: true

Size: 997 Bytes

Versions: 1

Compression:

Stored size: 997 Bytes

Contents

class <%= controller_name %> < ApplicationController

  expose(:<%= file_name.pluralize %>)
  expose(:<%= file_name %>, finder: :find_by_slug, finder_parameter: :slug)
  expose(:new_<%= file_name %>, model: <%= klass %>)
  expose(:slug) { params[:slug] }

  # Move this to the ApplicationController if you want to have
  # the navigation in your Application Layout
  expose(:<%= file_name%>_slugs ) { <%= klass %>.select(:slug).map(&:slug) }

  def show
    if template_exists? "<%= file_names %>/#{slug.underscore}"
      render slug.underscore
    else
      render "show"
    end
  end

  def create
    if new_<%= file_name %>.save
      redirect_to slug_path(new_<%= file_name %>.slug)
    else
      render 'new'
    end
  end

  def update
    if <%= file_name %>.save
      redirect_to slug_path(<%= file_name %>.slug)
    else
      render 'edit'
    end
  end

  def destroy
    <%= file_name %>.destroy
    redirect_to :root, message: "#{<%= file_name %>.name} was deleted."
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
buildybuild-0.0.1 lib/generators/buildybuild/cms/templates/cms_controller.rb