Rails 4: checkboxes with a has_many through -


i'm building application has assign assignment multiple employers.

i have build these models:

#assignment.rb class assignment < activerecord::base     has_many :employer_assignments     has_many :employers, :through => :employer_assignments end  #employer.rb class employer < activerecord::base     has_many :employer_assignments     has_many :assignments, :through => :employer_assignments end  #employer_assignment.rb class employerassignment < activerecord::base     belongs_to :employer     belongs_to :assignment end 

and want form save employer_assignment table following code used form doesn't work.

<div class="field">     <%= f.label :employer_ids %><br />     <%= collection_check_boxes(:assignment, :employer_ids, employer.all, :id, :name) %> </div> 

i did add :employer_ids assignment controller try send form create assignment doesn't create records in employer_assignment table. when add them via console ( assignment.last.employers << employer.all ) works fine. i'm sure i'm missing can't figure out what.

thanks in advance.

you're getting unpermitted parameters: in log due strong parameters in rails4 (@emil-kampp mentioned this), after fresh rails generate, generated in controller. using code like:

class employerscontroller < applicationcontroller   # <snip>   def update     @employer.update(employer_params)   end    def employer_params     params.require(:employer).permit(:name, { :employer_ids => [] })   end end 

also see question on answers this. saves few cycles.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -