Administrate: Don't search my edit route for id

Created on 26 Jun 2019  路  5Comments  路  Source: thoughtbot/administrate

The route through the slug field and not id see:

Screenshot 2019-06-26 16 18 51

The correct would be:

/admin/customers/1/edit

My controller:

module Admin
  class CustomersController < Admin::ApplicationController
  end
end

My dashboard:

require "administrate/base_dashboard"

class CustomerDashboard < Administrate::BaseDashboard
  ATTRIBUTE_TYPES = {
    company: Field::BelongsTo,
    id: Field::Number,
    name: Field::String,
    slug: Field::String,
    created_at: Field::DateTime,
    updated_at: Field::DateTime,
    contract_start_at: Field::DateTime,
    contract_end_at: Field::DateTime,
    observation: Field::Text,
    logo: Field::String,
    cnpj: Field::String,
  }.freeze

  COLLECTION_ATTRIBUTES = [
    :company,
    :id,
    :name,
  ].freeze

  SHOW_PAGE_ATTRIBUTES = [
    :company,
    :id,
    :name,
    :slug,
    :created_at,
    :updated_at,
    :contract_start_at,
    :contract_end_at,
    :observation,
    :logo,
    :cnpj,
  ].freeze

  FORM_ATTRIBUTES = [
    :company,
    :name,
    :slug,
    :contract_start_at,
    :contract_end_at,
    :observation,
    :logo,
    :cnpj,
  ].freeze
end

Thak you for support.

Most helpful comment

worked with:

def find_resource(param)
  Customer.find_by!(slug: param)
end

thank you

All 5 comments

Probably you are using the FriendlyId gem.

Maybe you can solve this problem uncommenting the following code in your model:
app/controllers/admin/your_model_controller.rb Define a custom finder by overriding the `find_resource` method: def find_resource(param) YourModel.find_by!(slug: param) end

worked with:

def find_resource(param)
  Customer.find_by!(slug: param)
end

thank you

This issue can be closed?

@GeoffAbtion Yeah, I think you can close this issue. @rodrigovirgilio how about you?

Yes, you can close it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

conwayanderson picture conwayanderson  路  4Comments

steffenix picture steffenix  路  4Comments

ACPK picture ACPK  路  4Comments

stephenson picture stephenson  路  3Comments

trandoanhung1991 picture trandoanhung1991  路  3Comments