If anyone is interested... along the same lines as view templates, I
figured out how to create controller template to override the scaffold
controllers which rails 3 generates.

1. Create the following folders starting at the root folder of your
rails 3 app.

/lib/templates/rails/scaffold_controller

2. Create a controller.rb file inside the 'scaffold_controller'
folder.

3. Paste in the content as found at:

https://github.com/rails/rails/blob/master/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb

4. Then modify to suit your needs. In my case I am using
declarative_authorization, and I learned about respond_to and
respond_with from a railscast, so my controller.rb file is reduced to
the following:

---------
class <%= controller_class_name %>Controller < ApplicationController
  filter_resource_access
  respond_to :html, :xml

  def index
    @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
    respond_with (@<%= plural_table_name %>)
  end

  def show
    respond_with (@<%= singular_table_name %>)
  end

  def new
    respond_with (@<%= singular_table_name %>)
  end

  def edit
  end

  def create
    if @<%= singular_table_name %>.save
      flash[:notice] = '<%= human_name %> was successfully created.'
    end
    respond_with(@<%= singular_table_name %>, :location => <%=
plural_table_name %>_url)
  end

  def update
    if @<%= singular_table_name %>.update_attributes(params[:<%=
singular_table_name %>])
      flash[:notice] = '<%= human_name %> was successfully updated.'
    end
    respond_with(@<%= singular_table_name %>, :location => <%=
plural_table_name %>_url)
  end

  def destroy
    @<%= singular_table_name %>.destroy
    respond_with(@<%= singular_table_name %>, :location => <%=
plural_table_name %>_url)
  end

end
---------

HTH - Doug K.

-- 
You received this message because you are subscribed to the Google Groups 
"Haml" group.
To post to this group, send email to h...@googlegroups.com.
To unsubscribe from this group, send email to haml+unsubscr...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/haml?hl=en.

Reply via email to