Sha256: 7ec32af2b8aae77fd5275510868cd21ae13c10ea2639204698d5e08104cf9a68

Contents?: true

Size: 1.82 KB

Versions: 6

Compression:

Stored size: 1.82 KB

Contents

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

  before_filter :find_<%= sco_underscored %>, :only => [:show, :edit, :update, :destroy]
  before_filter :find_<%= sco_parent_underscored %>,  :only => [:index, :new, :create]


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

  def index
    @<%= sco_underscored_plural %> = @<%= sco_parent_underscored %>.<%= sco_underscored_plural %>
  end

  <% end -%>

  def show
  end


  def new
    @<%= sco_underscored %> = @<%= sco_parent_underscored %>.<%= sco_underscored_plural %>.build
  end


  def edit
  end


  def create
    @<%= sco_underscored %> = @<%= sco_parent_underscored %>.<%= sco_underscored_plural %>.build(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


  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


  def destroy
    @<%= sco_underscored %>.destroy
    redirect_to :back
  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_parent_underscored %>
      @<%= sco_parent_underscored %> = <%= sco_parent_class %>.find(params[:<%= sco_parent_underscored %>_id])
    end

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

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
schofield-0.0.6 generators/schofield_controller/templates/nested/controller.rb
schofield-0.0.5 generators/schofield_controller/templates/nested/controller.rb
schofield-0.0.4 generators/schofield_controller/templates/nested/controller.rb
schofield-0.0.3 generators/schofield_controller/templates/nested/controller.rb
schofield-0.0.2 generators/schofield_controller/templates/nested/controller.rb
schofield-0.0.1 generators/schofield_controller/templates/nested/controller.rb