In a User Registration Form I am unable to enter data collected from multiple checkboxes and insert it into my database.
I am using PostgreSQL, Rails version- 4.0.1,Ruby - 1.9.3.
Here is my View code(new.html.erb)
div class="field col-md-5"> <%= form_for(@user) do |f|%> <%= render 'shared/error_messages' %> <div class="container"> <% flash.each do |key, value| %> <div class="alert alert-<%= key %>"><%= value %></div> <% end %> </div> <%= f.label :fname,"First Name" %> <%= f.text_field :fname,:class=>"form-control" %> <%= f.label :email %> <%= f.text_field :email,:class=>"form-control" %> <%= f.label :expertise,"Kindly select your field of expertise" %> <%= f.label :expertise,"Fundraising" %> <%= f.check_box(:expertise,:value=>"Fundraising") %> <%= f.label :expertise,"Enhancing Sales" %> <%= f.check_box(:expertise,:value=>"Enhancing Sales") %> <br> <%= f.label :expertise,"Marketing" %> <%= f.check_box(:expertise,:value=>"Marketing") %> <%= f.submit "Create my account", class: "btn btn-large btn-primary" %> <% end %> </div> <h4>or</h4> <%=button_to "Sign Up with LinkedIn", login_path, :method => :post,class: "btn btn-large btn-primary" %> </div> <% end %>
When I run the web application with this code, all the text field’s (such as first name) data gets entered into the database but any of the checkboxes data doesn’t get stored.
Could please tell why is this happening so?
I want my Model’s Database expertise column should get populated by the strings assigned to value symbol, defined along with each checkbox as you can see above.
I have an idea of making an hash in which each string is mapped to a an id and the expertise is column would then store these set of unique id separated by commas. We would the iterate over these numbers and find their corresponding key and print that key string on the page when required.
[1 =>"Fund Raising",2 => "Marketing",...]
But don’t have a clue how to write code for this, any suggestion on this line would be appreciated.
Also you have a better strategy to tackle this problem please do tell.
Thanks in advance
PS - The Model “Mentor” has this column expertise in its database table. Would appreciate a solution without changing this hierarchy.