Class: Admin::Kitsune::RecordsController
- Inherits:
-
KitsuneController
- Object
- KitsuneController
- Admin::Kitsune::RecordsController
- Defined in:
- app/controllers/admin/kitsune/records_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/admin/kitsune/records_controller.rb', line 22 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 @model.run_hooks(:before_save, @record) 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 |
#destroy ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/controllers/admin/kitsune/records_controller.rb', line 78 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 |
#edit ⇒ Object
49 50 51 52 |
# File 'app/controllers/admin/kitsune/records_controller.rb', line 49 def edit @model.run_hooks(:on_new, @record) @model.run_hooks(:on_edit, @record) end |
#index ⇒ Object
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 |
#new ⇒ Object
17 18 19 20 |
# File 'app/controllers/admin/kitsune/records_controller.rb', line 17 def new @record = @model.new_record @model.run_hooks(:on_new, @record) end |
#update ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/admin/kitsune/records_controller.rb', line 54 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 @model.run_hooks(:before_save, @record) 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 |