class <%= controller_class_name %>Controller < ApplicationController <% unless suffix -%> def index end <% end -%> <% for action in unscaffolded_actions -%> def <%= action %><%= suffix %> end <% end -%> def return_to_main # If you have multiple scaffolds on the same view then you will want to change this to # to whatever controller/action shows all the views # (ex: redirect_to :controller => 'AdminConsole', :action => 'index') redirect_to :action => 'index' end def list<%= suffix %> @<%= plural_name %> = <%= model_name %>.find :all render :layout => false end def new<%= suffix %> @<%= singular_name %> = <%= model_name %>.new if request.xhr? @temp_id = Time.new.to_i @headers['<%= singular_name %>-id'] = @temp_id @headers['Content-Type'] = 'text/html; charset=utf-8' render :layout => false # If you want to send an error message: # render :inline => "Error text goes here", :layout => false, :status => 500 end end def create<%= suffix %> @<%= singular_name %> = <%= model_name %>.new(params[:<%= singular_name %>]) if @<%= singular_name %>.save if request.xhr? @headers['<%= singular_name %>-id'] = @<%= singular_name %>.id @headers['Content-Type'] = 'text/html; charset=utf-8' render :partial => '<%= singular_name %><%= suffix %>', :layout => false, :locals => { :hidden => true } else return_to_main end else render :partial => 'form_errors', :layout => false, :status => 500 if request.xhr? render :action => 'new' if not request.xhr? end end def edit<%= suffix %> @<%= singular_name %> = <%= model_name %>.find(params[:id]) render :layout => false if request.xhr? end def update @<%= singular_name %> = <%= model_name %>.find(params[:id]) if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>]) render :partial => '<%= singular_name %><%= suffix %>', :layout => false, :locals => { :hidden => true } if request.xhr? return_to_main if not request.xhr? else render :partial => 'form_errors', :layout => false, :status => 500 if request.xhr? render :action => 'edit' if not request.xhr? end end def destroy<%= suffix %> <%= model_name %>.find(params[:id]).destroy render :nothing => true if request.xhr? return_to_main if not request.xhr? end end