Module: ScaffoldMarkup::Controllers::Base

Defined in:
lib/scaffold_markup/controllers/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#resource_classObject (readonly)

Returns the value of attribute resource_class.



4
5
6
# File 'lib/scaffold_markup/controllers/base.rb', line 4

def resource_class
  @resource_class
end

Class Method Details

.included(base) ⇒ Object



6
7
8
# File 'lib/scaffold_markup/controllers/base.rb', line 6

def self.included(base)
  base.before_filter :identify_resource
end

Instance Method Details

#createObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/scaffold_markup/controllers/base.rb', line 26

def create
  @model = resource_class.new(params[resource_class.model_name.underscore])
  if @model.save
    flash_message = "#{resource_class.model_name.human} successfully created"
    if params[:save_and_new]
      flash[:success] = flash_message
      redirect_to :action => :new
    else
      flash.now[:success] = flash_message
      render :show
    end
  else
    render :new
  end
end

#destroyObject



52
53
54
55
56
57
58
59
60
# File 'lib/scaffold_markup/controllers/base.rb', line 52

def destroy
  @model = resource_class.find(params[:id])
  if @model.destroy
    flash[:warning] = "#{resource_class.model_name.human} successfully removed"
  else
    flash[:danger] = "#{resource_class.model_name.human} could not be deleted"
  end
  redirect_to :action => :index
end

#editObject



22
23
24
# File 'lib/scaffold_markup/controllers/base.rb', line 22

def edit
  @model = resource_class.find(params[:id])
end

#indexObject



10
11
12
# File 'lib/scaffold_markup/controllers/base.rb', line 10

def index
  @collection = resource_class.page(params[:page])
end

#newObject



18
19
20
# File 'lib/scaffold_markup/controllers/base.rb', line 18

def new
  @model = resource_class.new
end

#showObject



14
15
16
# File 'lib/scaffold_markup/controllers/base.rb', line 14

def show
  @model = resource_class.find(params[:id])
end

#updateObject



42
43
44
45
46
47
48
49
50
# File 'lib/scaffold_markup/controllers/base.rb', line 42

def update
  @model = resource_class.find(params[:id])
  if @model.update_attributes(params[resource_class.model_name.underscore])
    flash.now[:success] = "#{resource_class.model_name.human} successfully updated"
    render :show
  else
    render :edit
  end
end