Virtual attributes in Rails 4 from Rails 3 -


I am making a Rail 4.10 app and I am using code from my Rail 3.2 app. In this app, I get a form where I add a virtual attribute which is called Group_ID and then use after_save to add a group for the user.

In my 3.2 code:

  attr_accessor: group_ids after_save: add_groups def add_groups if group_ids.present? Self.assignments.user_groups.delete_all group_ids.reject! (And: empty?) Group_ids.each do | Group | Assignment = assignment.Nana Assignment.Signable_ID = Group Assignment.Signable_type = "User Group" assignment. Backend_user_id = self.id self.assignments & lt; & Lt; Assignment end and end   

In my 4.10 code:

  Controller: params.require (: backend_user) .permit (: First name, last name, group_ids)   

How can I use the Add_groups method in 4.10?

It looks like the group_ids in the controller code is correctly whitelisted Not being added, which results in group_ids is not being set which will be in your after_save callback in group_ids.present? Returning status false Therefore, no statement in the callback is executed.

To minimize it, after_save callback add_groups is executing but it is not doing anything

it To resolve, you should whitelist group_ids in your code control code:

  parameter is needed (backend_user). Paramet (: First Name, Last Name, Group_ID => [])    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -