Add new field to the database with Rails

2

I inserted a new column in my table contents and also includes the field in the form with the same column name in the (client_id) creation table, but this data is not entered when I create a new record.

I already added symbol to the controller;

params.require(:content).permit(:title, :content, :client_alteration, :target, :scheduled_to, :status, :comment, :client_id)

HTML

<div class="field">
<%= f.label 'Cliente' %>
<%= select_tag 'client_id', options_from_collection_for_select(@clients, 'id', 'name') %>

    
asked by anonymous 28.09.2016 / 18:41

2 answers

1

@Rafael, the problem is that you are not passing client_id as an attribute contents (using f ) on your form, in cases like yours, I particularly like to use collection_select , it looks something like this:

<div class="field">
  <%= f.label 'Cliente' %>
  <%= f.collection_select :client_id, @clients, :id, :name %>
</div>
    
29.09.2016 / 01:52
0

select_tag creates a specific field within params and not within content . You need the field client_id within content (params[:content][:client_id]) , but the field being passed is probably params[:client_id] .

    
28.09.2016 / 22:20