I got this error when going to one my ressources called "Fils":
PG::UndefinedColumn: ERROR: column users.contact_id does not exist
LINE 1: SELECT "users".* FROM "users" WHERE "users"."contact_id" = ...
^
: SELECT "users".* FROM "users" WHERE "users"."contact_id" = $1 LIMIT 1
I don't understand why the query looks on user.contact_id
instead of fil.contact_id
(I'm beginning in rails but i don't think it's the good behavior)
Fil table on schema.rb :
create_table "fils", force: :cascade do |t|
t.integer "contact_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.string "channel"
end
Fil model :
class Fil < ActiveRecord::Base
before_validation :check_or_connect_messageries, :if =>:new_record?
has_one :contact, class_name: "User", :foreign_key => "contact_id"
has_one :user, class_name: "User", :foreign_key => "user_id"
validates :contact_id, presence: true
validates :user_id, presence: true
before_create :set_channel
after_find :set_channel # des fois que
User model :
class User < ActiveRecord::Base
before_validation :check_genres
before_validation :set_image
before_validation :init_attrs
before_save :create_mangopay_bank_account
before_create :set_name
before_create :create_mangopay
after_create :set_centres_interets
after_create :set_preferences_musicales
after_create :check_on_create
after_update :check_on_update
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
has_one :preferences_voyage, dependent: :destroy
has_one :verification, dependent: :destroy
has_many :badges, dependent: :destroy
has_many :favoris , dependent: :destroy
has_many :centres_interets, dependent: :destroy
has_many :preferences_musicales, dependent: :destroy
has_many :recommandations, dependent: :destroy
has_many :reputations, dependent: :destroy
has_many :reservations, dependent: :destroy
has_many :routes, dependent: :destroy
has_many :trajets_reguliers, dependent: :destroy
has_many :vehicules, dependent: :destroy
has_many :notifications, dependent: :destroy
validates :date_naissance, presence: true
validates :first_name, presence: true
validates :last_name, presence: true
attr_accessor :points_communs
attr_accessor :modele # created/booked/archived
attr_accessor :peut_laisser_commentaire
attr_accessor :est_abonne
attr_accessor :est_bloque
attr_accessor :a_vehicule
admin/user.rb :
ActiveAdmin.register User do
menu parent: "Utilisateurs"
permit_params :name, :nickname, :email , :image, :genre,:statut, :fume, :etudes
index do
selectable_column
id_column
column :name
column :nickname
column :email
column "Image" do |user|
image_tag user.image, size: "50"
end
column :genre
column :statut
column :fume
column :etudes
column :profession
actions
end
end
It should be Fil belongs_to User
and User has_one Fil
since the lookup happens in the fils-table.
A good basic read can be found here: http://guides.rubyonrails.org/association_basics.html#the-has-one-association
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.