I'm trying to submit a simple form using rails.
class BibliographiesController < ApplicationController
def creer #this has been localized for create
@bibliography = Bibliography.new(bibliographie_params)
@bibliography.save
redirect_to @bibliography
end
#etc etc
private
def bibliographie_params
params.require(:bibliographie).permit(:titre, :soustitre, :auteur_un, :auteur_deux, :auteur_trois, :auteur_quatre, :genre, :recueil, :review, :revue_numero, :annee, :revue_page, :editeur, :lieu, :commentaire)
end
end
The migration file contains the same fields. titre and soustitre are both strings and auteur_un is an integer.
When I submit the form, I get an error, which is :
NameError in BibliographiesController#creer
uninitialized constant Bibliography::AuteurUn
the params_hash contains :
"bibliographie"=>{
"titre"=>"La vie urbaine à Douai au Moyen-Âge",
"soustitre"=>"rien",
"auteur_un"=>"1",
"genre"=>"source",
"recueil"=>"aucun",
"review"=>"",
"revue_numero"=>"",
"annee"=>"",
"revue_page"=>"",
"editeur"=>"",
"lieu"=>"",
"commentaire"=>""}
This is my Bibliography class :
class Bibliography < ApplicationRecord
has_one :auteur_un, foreign_key: "auteurs_id"
has_one :auteur_deux, foreign_key: "auteurs_id"
has_one :auteur_trois, foreign_key: "auteurs_id"
has_one :aauteur_quatre, foreign_key: "auteurs_id"
has_one :review, foreign_key: "reviews_id"
end
It seems like rails is expecting auteur_un to be a class or constant. But I don't see why.
Thanks