class <%= class_name %>Controller < Admin::AdminController before_filter :find_<%= sco_underscored %>, :only => [<%= filter_actions %w( show edit update destroy) %>] <%- sco_parents.each do |parent| -%> before_filter :find_<%= parent[:underscored] %>, :except => [<%= filter_actions %w( destroy sort ) %>] <%- end -%> before_filter :titles, :except => [<%= filter_actions %w( destroy sort ) %>] <% if actions.include?('index') -%> def index @<%= sco_underscored_plural %> = @<%= sco_parents.last[:underscored] %>.<%= sco_underscored_plural %> end <% end -%> <% if actions.include?('show') -%> def show end <% end -%> <% if actions.include?('new') -%> def new @<%= sco_underscored %> = @<%= sco_parents.last[:underscored] %>.<%= sco_underscored_plural %>.build end <% end -%> <% if actions.include?('edit') -%> def edit end <% end -%> <% if actions.include?('create') -%> def create @<%= sco_underscored %> = @<%= sco_parents.last[: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 <% 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_plural %>].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 <% sco_parents.each_with_index do |parent, index| -%> def find_<%= parent[:underscored] %> @<%= parent[:underscored] %> = params[:<%= parent[:underscored] %>_id].present? ? <%= parent[:class] %>.find(params[:<%= parent[:underscored] %>_id]) : @<%= index == 0 ? sco_underscored : sco_parents[index-1][:underscored] %>.<%= parent[:underscored] %> end <% end -%> def find_<%= sco_underscored %> @<%= sco_underscored %> = <%= sco_class %>.find(params[:id]) end def titles <%- sco_parents.reverse_each do |parent| -%> add_breadcrumb '<%= parent[:titleized_plural] %>', admin_<%= parent[:underscored_plural] %>_path add_breadcrumb @<%= parent[:underscored] %> <%- end -%> add_breadcrumb '<%= sco_titleized_plural %>' add_breadcrumb @<%= sco_underscored %> end end