0

I am developing job portal using rails 4. In my application employer can post a job. In job post form, I want to provide multiple check-box for category names , so that while posting a job an employer could select multiple categories. How can I do this and how to save it to my job model?

Here is my view

<!-- check-boxs -->
              <div class="form-group">
                <label>Job Categories</label>
                <div class="row clearfix">
                  <%JobCategory.all.each do |category|%>
                  <div class="col-md-4">
                    <div class="checkbox flat-checkbox">
                      <label>
                        <input type="checkbox"> 
                        <span class="fa fa-check"></span>
                        <%=category.name%>
                      </label>
                    </div>
                  </div>
                <% end %>                     
                </div>
              </div><!-- end checkboxs -->
MZaragoza
  • 10,108
  • 9
  • 71
  • 116
kali
  • 133
  • 1
  • 7
  • See this: http://stackoverflow.com/questions/21896632/submit-ul-list-as-parameter-array-in-rails-4-form-adding-params-values-to-par The question started out different, but the answer I finally used is multiple check boxes. The trick is that when you are in the _form for the `new` action you have one form for the boxes, but to pull the collection from the DB in a `show` or `edit` action you need a hidden field. – Beartech Mar 31 '15 at 06:07
  • thank you ...i will chk for it :) – kali Mar 31 '15 at 06:10
  • Also, when you want to build a group of boxes from a collection of categories, you could pass the .erb file a variable with `JobCategory.pluck(:name)` and use that array in a collection. – Beartech Mar 31 '15 at 17:54

1 Answers1

0

ActiveRecord::Base.serialize Reference Link

For example :

class User < ActiveRecord::Base
  serialize :job_category_ids
end

job = Job.create(:scholarship => {"name" => "test", "job_category_ids" => ["1", "2"]})
Job.find(job_category.id).scholarship # => { "name" => "test", "job_category_ids" => ["1", "2"] }

Take a look at collection_check_box usage in RoR for more help

Happy Hacking

Community
  • 1
  • 1
MZaragoza
  • 10,108
  • 9
  • 71
  • 116