Class: Motor::ConfigsController

Inherits:
ApiBaseController show all
Defined in:
app/controllers/motor/configs_controller.rb

Instance Method Summary collapse

Methods included from CurrentAbility

#current_ability

Methods included from CurrentUserMethod

#current_user

Instance Method Details

#createObject


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/motor/configs_controller.rb', line 13

def create
  @config =
    Motor::Config.find_or_initialize_by(key: @config.key).tap do |config|
      config.value = @config.value
    end

  @config.save!
  Motor::Configs::WriteToFile.call

  render json: { data: Motor::ApiQuery::BuildJson.call(@config, params, current_ability) }
rescue ActiveRecord::RecordNotUnique
  retry
end

#indexObject


9
10
11
# File 'app/controllers/motor/configs_controller.rb', line 9

def index
  render json: { data: Motor::ApiQuery::BuildJson.call(@configs, params, current_ability) }
end