First table id does not click on BD

Asked

Viewed 86 times

4

I’m trying to create a simple contact schedule with two tables: Being one of them empresa :nome and the other contatos :nome :telefone :email... I created the two tables and put a Foreign_key in the second that will receive the empresa_id of the first.

In the form of the second table I put a f.collection_select of the following maeira: <%= f.collection_select :empresa,Empresa.order('nome Asc'),:id, :nome,{prompt: "Selecione uma empresa"},{class: "form-control"} %> . It works only when I select the company and include the other fields the company id not saved in the Bank. Could you help me by telling me where I’m going wrong?

  • 1

    Welcome to Stackoverflow! Apparently the collection_select, We need more information: Do you mind editing the question and putting the controller code?

  • 1

    @Andrey Then take a look at the Magic links like [pt.so] in http://meta.pt.stackoverflow.com/questions/1616/quais-s%C3%A3o-todos-os-Magic-links-que-possu%C3%Admos helps to decrease the number of

  • 1

    @Caputo I always forget it =P I’ll try to remember in the next

1 answer

3

I was able to solve it this way:

<%= f.collection_select(:empresa_id, Empresa.all.order(:nome), :id, :nome {prompt :true}) %>

And so it worked!

  • 1

    Good that you were able to solve your problem, but if possible try to better explain what your problem was and how you solved it, so users facing similar problems in the future can benefit from your answer.

  • Very good! Just mark your answer as correct and give more information about what the problem was, as @Fernando said

  • Correct. There were two tables and the select presented all the fields of the parent table. But at the time that saved the data in the BD did not enter the value of the parent table id in the child table. But with this f.collection_select formatting the problem has been fixed and you have entered the parent table id value in the child table.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.