Class: Spree::Admin::LocationsController

Inherits:
ResourceController
  • Object
show all
Defined in:
app/controllers/spree/admin/locations_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/spree/admin/locations_controller.rb', line 9

def create
  if location_exist?
    flash[:error] = I18n.t('location.already_exist')
    render :new, status: :unprocessable_entity and return
  end

  location = model_class.new(permitted_resource_params)

  if location.save
    flash[:success] = flash_message_for(location, :successfully_created)
    redirect_to spree.admin_locations_path
  else
    flash.now[:error] = location.errors.full_messages.to_sentence
    render :new, status: :unprocessable_entity
  end
end

#indexObject



4
5
6
7
# File 'app/controllers/spree/admin/locations_controller.rb', line 4

def index
  @search = model_class.ransack(params[:q])
  @locations = @search.result.order(created_at: :desc).page(params[:page]).per(15)
end