Sha256: c3fa95e9e86178ecd9354287bdffcbff93ad72ead22ef13e9df45d14b7c68e3c

Contents?: true

Size: 1.04 KB

Versions: 6

Compression:

Stored size: 1.04 KB

Contents

module Gaku
  module Admin
    class StatesController < Admin::BaseController

      load_and_authorize_resource class: State

      respond_to :js, :html

      inherit_resources

      before_filter :count, only: %i(create destroy index)
      before_filter :load_country_preset, only: :index
      before_filter :load_data

      def country_states
        @country = Country.where(iso: params[:state][:country_iso]).first
        @states = @country.states
        respond_with @states
      end

      protected

      def resource_params
        return [] if request.get?
        [params.require(:state).permit(attributes)]
      end

      private

      def attributes
        %i(name abbr name_ascii code country_iso)
      end

      def load_data
        @countries = Country.all.map { |c| [c, c.iso ]}
      end

      def load_country_preset
        @country_preset ||= Preset.get('address_country')
        @default_country = Country.where(iso: @country_preset).first
      end

      def count
        @count = State.count
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
gaku_core-0.0.3 app/controllers/gaku/admin/states_controller.rb
gaku-0.0.3 core/app/controllers/gaku/admin/states_controller.rb
gaku-0.0.2 core/app/controllers/gaku/admin/states_controller.rb
gaku_core-0.0.2 app/controllers/gaku/admin/states_controller.rb
gaku-0.0.1 core/app/controllers/gaku/admin/states_controller.rb
gaku_core-0.0.1 app/controllers/gaku/admin/states_controller.rb