controller.rb 1.4 KB
Newer Older
1
class <%= controller_class_name %>Controller < ApplicationController
2 3 4 5 6 7 8 9 10 11 12 13 14
<% unless suffix -%>
  def index
    list
    render_action 'list'
  end
<% end -%>

<% for action in unscaffolded_actions -%>
  def <%= action %><%= suffix %>
  end

<% end -%>
  def list<%= suffix %>
15
    @<%= plural_name %> = <%= model_name %>.find_all
16 17 18
  end

  def show<%= suffix %>
19
    @<%= singular_name %> = <%= model_name %>.find(@params[:id])
20 21 22
  end

  def new<%= suffix %>
23
    @<%= singular_name %> = <%= model_name %>.new
24 25 26
  end

  def create<%= suffix %>
27
    @<%= singular_name %> = <%= model_name %>.new(@params[:<%= singular_name %>])
28
    if @<%= singular_name %>.save
29
      flash['notice'] = '<%= model_name %> was successfully created.'
30 31 32 33 34 35 36
      redirect_to :action => 'list<%= suffix %>'
    else
      render_action 'new<%= suffix %>'
    end
  end

  def edit<%= suffix %>
37
    @<%= singular_name %> = <%= model_name %>.find(@params[:id])
38 39 40
  end

  def update
41 42 43 44
    @<%= singular_name %> = <%= model_name %>.find(@params[:id])
    if @<%= singular_name %>.update_attributes(@params[:<%= singular_name %>])
      flash['notice'] = '<%= model_name %> was successfully updated.'
      redirect_to :action => 'show<%= suffix %>', :id => @<%= singular_name %>
45 46 47 48 49 50
    else
      render_action 'edit<%= suffix %>'
    end
  end

  def destroy<%= suffix %>
51
    <%= model_name %>.find(@params[:id]).destroy
52 53 54
    redirect_to :action => 'list<%= suffix %>'
  end
end