How to insert values from a Select field into the database

2

I am a beginner in Ruby on Rails and I need to add a Select field to the user registry form, so I can add a "Type" to the user to be registered. I want to automatically populate the fields when editing and viewing a user record.

I'm implementing a system for a Graph, which has the "User", "Director" and "Graph" profiles. My Select is structured as follows in _form of user:

<div class="field">
  <%= f.label :tipo %><br>
  <%= f.select :tipo, ['usuario', 'grafica', 'diretor'] %>
</div>

Select values are not being entered into the database! How should I proceed?

    
asked by anonymous 27.07.2014 / 00:32

2 answers

3

If you are using Rails 4, you have to look at the strog paramters, if you are allowing access to the attribute, follow the example method:

def your_model_params
  params.require(:account).permit(:tipo)
end

If you are using Rails 3, make sure the attribute is accessible. An example of select:

<%= f.select :email_provider, options_for_select(%w[Provider1 Provider2]) %>

I hope to have helped, a good start is Rails' guide:)

    
12.08.2014 / 17:12
2

So I understand that's what you need

f.select(:tipo, [['usuario', 'usuario'], ['grafica', 'grafica'], ['diretor', 'diretor'] })
    
12.08.2014 / 15:09