Class: Admin::Kitsune::RecordsController

Inherits:
KitsuneController
  • Object
show all
Defined in:
app/controllers/admin/kitsune/records_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/admin/kitsune/records_controller.rb', line 21

def create
  if request.xhr?
    render :text => "Foo"
  else
    if @model.is_sti? && params[params[:model_id].underscore][@model.sti_column].present?
      sti_model = Kitsune::Inspector.new(params[params[:model_id].underscore].delete(@model.sti_column).constantize)
      @record = sti_model.new_record(params[params[:model_id].underscore])
    else
      @record = @model.new_record(params[params[:model_id].underscore])
    end
    if @record.save
      flash[:notice] = "Record Saved"
			if params[:redirect]
				klass = params[:redirect].gsub(/_id$/, '').classify.constantize
				record = klass.find(params[:redirect_id])
				redirect_to url_for(:controller => 'admin/kitsune/records', :model_id => klass.to_s, :id => params[:redirect_id], :action => :edit)
			else
				redirect_to url_for(:controller => 'admin/kitsune/records', :model_id => @model.class_name)
			end
    else
      flash[:notice] = "Could not save record"
      render 'new'
    end
  end
end

#destroyObject



71
72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/admin/kitsune/records_controller.rb', line 71

def destroy
  @record.destroy
  flash[:notice] = "Record Deleted"
if params[:redirect]
	klass = params[:redirect].gsub(/_id$/, '').classify.constantize
	record = klass.find(params[:redirect_id])
	redirect_to url_for(:controller => 'admin/kitsune/records', :model_id => klass.to_s, :id => params[:redirect_id], :action => :edit)
else
	redirect_to url_for(:controller => 'admin/kitsune/records', :model_id => @model.class_name)
end
end

#indexObject



7
8
9
10
11
12
13
14
15
# File 'app/controllers/admin/kitsune/records_controller.rb', line 7

def index
  order, @sort_param, @sort_dir = @model.order_by, nil, nil
  if params[:sort]
    @sort_param = params[:sort]
    @sort_dir = params[:sort_dir]
    order = "#{params[:sort]} #{params[:sort_dir]}"
  end
  @records = @model.paginate(:page => params[:page], :order => order)
end

#newObject



17
18
19
# File 'app/controllers/admin/kitsune/records_controller.rb', line 17

def new
  @record = @model.new_record
end

#updateObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/admin/kitsune/records_controller.rb', line 47

def update
  
  if @model.is_sti_child? && params[params[:model_id].underscore][:type]
    if params[params[:model_id].underscore][:type].to_s != @record.type.to_s
      @record.type = params[params[:model_id].underscore][:type]
      @record.save
    end
  end
  
  if @record.update_attributes(params[params[:model_id].underscore])
    flash[:notice] = "Record Saved"
	if params[:redirect]
		klass = params[:redirect].gsub(/_id$/, '').classify.constantize
		record = klass.find(params[:redirect_id])
		redirect_to url_for(:controller => 'admin/kitsune/records', :model_id => klass.to_s, :id => params[:redirect_id], :action => :edit)
	else
		redirect_to url_for(:controller => 'admin/kitsune/records', :model_id => @model.class_name)
	end
  else
    flash[:notice] = "Could not save record"
    render 'edit'
  end
end