我正在尝试创建一个新用户,但用户 has_one Musician 和 Musician belongs_to User。在创建此关系之前,我的创建工作正常,但现在我收到错误消息:
期待音乐家,得到弦乐
但我不知道为什么会这样,我猜是我的 user_id 的问题,就像这个主题Country expected, got String error但我不确定,不知道如何解决它,这是我的用户控制器
def create
@user = User.new(params[:user])
if params[:user].musician
@user.musico = Musician.New
else
@user.estudio = Studio.new
end
if @user.save
sign_in @user
flash[:success] = "Welcome!!"
redirect_to @user
else
render 'new'
end
end
这是提交
{"utf8"=>"✓",
"authenticity_token"=>"VjOUW75ocw8rw/rEqa076x9N/Oa/5AjMxBOmRGAaDAM=",
"user"=>{
"firstName"=>"Eduardo",
"lastName"=>"Almeida",
"email"=>"eduardo@teste.com.br",
"city"=>"Mogi",
"password"=>"[FILTERED]",
"password_confirmation"=>"[FILTERED]",
"musician"=>"true"},
"commit"=>"Criar Conta"}
编辑:表格
<%= form_for(@user) do |f| %>
<%= render 'shared/erros' %>
<%= f.label :firstName, "Nome" %>
<%= f.text_field :firstName%><br/>
<%= f.label :lastName, "Sobrenome" %>
<%= f.text_field :lastName%><br/>
<%= f.label :email, "Email"%>
<%= f.text_field :email%><br/>
<%= f.label :city, "Cidade"%>
<%= f.text_field :cidade%><br/>
<%= f.label :password, "Senha"%>
<%= f.password_field :password%><br/>
<%= f.label :password_confirmation, "Confirme a senha"%>
<%= f.password_field :password_confirmation%><br/>
<%= f.hidden_field :newMusico, :value => true%>
<%= f.submit "Criar Conta", class: "btn btn-large btn-primary" %>
<% end %>