Question

I have a user model and messages model with the following associations

user model user.rb

  has_many :sent_messages, dependent: :destroy,
  :class_name => 'Message',
  :primary_key=>'unique_id',
  :foreign_key => 'sender_id',
  :order => "messages.created_at DESC",
  :conditions => ["messages.sender_deleted = ?", false]

  has_many :received_messages, dependent: :destroy,
  :class_name => 'Message',
  :primary_key=>'unique_id',
  :foreign_key => 'recepient_id',
  :order => "messages.created_at DESC",
  :conditions => ["messages.recepient_deleted = ?", false]

message model message.rb

belongs_to :sender,
  :class_name => 'User',
  :primary_key => 'unique_id',
  :foreign_key => 'sender_id'
  belongs_to :recepient,
  :class_name => 'User',
  :primary_key => 'unique_id',
  :foreign_key => 'recepient_id'

in my admin panel with rails_admin, when i try to edit the user details, i get the following error undefined method unique_id for #<Message:0x00000005b5efa0>

Extracted source (around line #10):
7 selected = [config.abstract_model.get(related_id)]
8     else
 9      selected = form.object.send(field.name)
 10    end
 11    selected_ids = selected.map{|s| s.send(field.associated_primary_key)}
 12  
 13    current_action = params[:action].in?(['create', 'new']) ? 'create' : 'update'

anybody with help, i will highly appreciate.

am using gem devise for managing users, and rails_admin for managing admin

Was it helpful?

Solution

the database table you are referencing does not have a column unique_id. you might have forgotten to migrate something, or it's just a misconfiguration.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top