Sha256: 124b500271bb58903acdebaf1aee0b4502c7aa1b5a26163eb9c2c97d79343394

Contents?: true

Size: 1.78 KB

Versions: 2

Compression:

Stored size: 1.78 KB

Contents

class <%= class_name %>Controller < Admin::AdminController

  before_filter :find_<%= sco_underscored %>, :only => [<%= filter_actions %w( show edit update destroy) %>]


  <% if actions.include?('index') -%>
  
  def index
    @<%= sco_underscored_plural %> = <%= sco_class %>.all
  end
  
  <% end -%>
  <% if actions.include?('show') -%>
  
  def show
  end

  <% end -%>
  <% if actions.include?('new') -%>

  def new
    @<%= sco_underscored %> = <%= sco_class %>.new
  end
  
  <% end -%>
  <% if actions.include?('edit') -%>

  def edit
  end

  <% end -%>
  <% if actions.include?('create') -%>

  def create
    @<%= sco_underscored %> = <%= sco_class %>.new(params[:<%= sco_underscored %>])
    if @<%= sco_underscored %>.save
      flash[:notice] = '<%= sco_humanized_uc %> was successfully created.'
      redirect_to_form_referer
    else
      render :action => 'new'
    end
  end

  <% end -%>
  <% if actions.include?('update') -%>

  def update
    if @<%= sco_underscored %>.update_attributes(params[:<%= sco_underscored %>])
      flash[:notice] = '<%= sco_humanized_uc %> was successfully updated.'
      redirect_to_form_referer
    else
      render :action => 'edit'
    end
  end

  <% end -%>
  <% if actions.include?('destroy') -%>

  def destroy
    @<%= sco_underscored %>.destroy
    redirect_to :back
  end
  
  <% end -%>
  <% if actions.include?('sort') -%>
  
  def sort  
    params[:<%= sco_underscored %>].each_with_index do |id, index|  
      <%= sco_class %>.update_all(['position=?', index+1], ['id=?', id])  
    end  
    render :nothing => true  
  end
  
  <% end -%>
  <% for action in non_restful_actions -%>

  def <%= action %>
  end

  <% end -%>

  private

    def find_<%= sco_underscored %>
      @<%= sco_underscored %> = <%= sco_class %>.find(params[:id])
    end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
schofield-0.0.8 generators/schofield_controller/templates/unnested/controller.rb
schofield-0.0.7 generators/schofield_controller/templates/unnested/controller.rb