Sha256: c0b444f4371be4d4c258ccee5ae094e4144a576bf941c498540dfe431d58b0a1

Contents?: true

Size: 1.27 KB

Versions: 56

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

class Tramway::Admin::HasAndBelongsToManyRecordsController < ::Tramway::Admin::ApplicationController
  def create
    base_object = params[:model_class].constantize.find params[:object_id]
    form_class = params[:form].constantize
    record_form = form_class.new base_object
    sending_params = if params[params[:model_class].underscore].present?
                       params[params[:model_class].underscore]
                     else
                       params[form_class.associated_as]
                     end
    if record_form.submit sending_params
      redirect_to params[:redirect].present? ? params[:redirect] : record_path(base_object, model: base_object.class)
    else
      redirect_to params[:redirect].present? ? params[:redirect] : record_path(base_object, model: base_object.class)
    end
  end

  def destroy
    base_object = params[:model_class].constantize.find params[:object_id]
    record_form = params[:form].constantize.new base_object
    if record_form.submit params[:id]
      redirect_to params[:redirect].present? ? params[:redirect] : record_path(base_object, model: base_object.class)
    else
      redirect_to params[:redirect].present? ? params[:redirect] : record_path(base_object, model: base_object.class)
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
tramway-admin-5.0 app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb
tramway-admin-4.1.2.1 app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb
tramway-admin-4.1.2 app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb
tramway-admin-4.1.1.5 app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb
tramway-admin-4.1.1.4 app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb
tramway-admin-4.1.1.3 app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb
tramway-admin-4.1.1.2 app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb
tramway-admin-4.1.1.1 app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb
tramway-admin-4.1.1 app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb
tramway-admin-4.1.0.1 app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb
tramway-admin-4.1 app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb
tramway-admin-4.0.1.1 app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb
tramway-admin-4.0.1 app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb
tramway-admin-4.0.0.1 app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb
tramway-admin-4.0 app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb
tramway-admin-3.0.1.1 app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb
tramway-admin-3.0.1 app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb
tramway-admin-3.0 app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb
tramway-admin-2.1.3.3 app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb
tramway-admin-2.1.3.2 app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb