Sha256: 7448b98993a368aa2326bf8fc4bdcde6b3ada0507982453db6a30efe1537683a

Contents?: true

Size: 1.68 KB

Versions: 3

Compression:

Stored size: 1.68 KB

Contents

module Adminpanel
	module RestActionsHelper
		def index
      index! do |format|
        format.html { render "shared/index" }
      end
		end

		def show
			show! do |format|
				format.html { render "shared/show" }
			end
		end

		def new
			set_collections
      new! do |format|
        format.html { render "shared/new" }
      end
		end

		def create
      create! do |success, failure|
        success.html do
        	flash.now[:success] = I18n.t("action.save_success")
          render "shared/index"
        end
        failure.html do
					set_collections
        	render "shared/new"
				end
      end
		end

		def edit
      edit! do |format|
        format.html do
        	set_collections
        	render "shared/edit"
        end
      end
		end

		def update
      update! do |success, failure|
        success.html do
        	flash.now[:success] = I18n.t("action.save_success")
        	render "shared/index"
        end
        failure.html do
        	set_collections
        	render "shared/edit"
        end
      end
		end

		def destroy
			destroy! do |format|
				format.html { render "shared/index" }
			end
		end

	private

		def set_collections
			@collections = {}
			set_belongs_to_collections
			@model.has_many_relationships.each do |class_variable|
				@collections.merge!({"#{class_variable}" => class_variable.find(:all)})
			end
		end

		def set_belongs_to_collections
			@model.belongs_to_relationships.each do |class_variable|
				if class_variable.respond_to?("of_model")
					@collections.merge!({"#{class_variable}" => class_variable.of_model(@model.display_name)})
				else
					@collections.merge!({"#{class_variable}" => class_variable.find(:all)})
				end
			end
		end
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
adminpanel-1.2.7 app/helpers/adminpanel/rest_actions_helper.rb
adminpanel-1.2.6 app/helpers/adminpanel/rest_actions_helper.rb
adminpanel-1.2.5 app/helpers/adminpanel/rest_actions_helper.rb