ruby-on-railsattributesruby-on-rails-5mass-assignment

Upgrade to Rails 5: while saving a record "id" is assigned primary key value instead of a number


In my table, primary key (my_id) is a string (combination of letters and numbers) and 'id' is a numeric column. Since rails 5 doesn't allow attr_accessible, I added the private method to controller params.require(:model_name).permit(:list_of_attributes). Now when I try to add a new record to this table, "id" takes the value of "my_id" (primary key). I was expecting "id" to be an increment number but this behavior started after removing attr_accessible. Has anyone faced this issue?


Solution

  • @model.attributes["id"] this worked.