0

RecordNotFound Issue in Rails

I see the above issue while accessing active admin show page for model "campaign". This might be due to friendly_id gem, but I'm unable to identify what exactly the issue is. My campaign.rb file looks like following:

class Campaign < ApplicationRecord
  extend FriendlyId
  friendly_id :title, use: [:slugged, :history]

  belongs_to :appeal
  belongs_to :user
  has_many :donations, dependent: :destroy
  has_many :slugs, class_name: "FriendlyId::Slug", as: :sluggable, dependent: :destroy

  validates :title, presence: true
  validates :description, presence: true
  validates :appeal_id, uniqueness: { scope: :user_id }

  def normalize_friendly_id(value)
    value.to_s.parameterize(preserve_case: true)
  end

  def self.first_by_friendly_id(id)
    super(id.split("-").map(&:capitalize).join("-"))
  end

  private

  def should_generate_new_friendly_id?
    slug.blank? || title_changed?
  end
end

and "campaigns.rb" contains:

ActiveAdmin.register Campaign do

  # See permitted parameters documentation:
  # https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
  #
  # Uncomment all parameters which should be permitted for assignment
  #
  permit_params :title, :description, :appeal_id, :user_id, :slug
  #
  # or
  #
  # permit_params do
  #   permitted = [:title, :description, :appeal_id, :user_id, :slug]
  #   permitted << :other if params[:action] == 'create' && current_user.admin?
  #   permitted
  # end
  
end
Fuaad
  • 197
  • 15
  • do you have a campaign with that id? – Haumer Oct 06 '22 at 07:58
  • Actually, the id is an integer value. But the the id unable to be found here is its friendly-id slug. I mean to say that its searching through friendly_id slug not by the real id. – Fuaad Oct 06 '22 at 13:16
  • This post has 3 viable answers: https://stackoverflow.com/questions/27032902/activeadmin-with-friendly-id – Chiperific Oct 07 '22 at 15:52

0 Answers0