Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. schema "users" do
  2. field :name, :string
  3. field :email, :string
  4. field :active, :boolean, default: true
  5. has_many :products, TestExAdmin.Product
  6. has_many :noids, TestExAdmin.Noid
  7. many_to_many :roles, TestExAdmin.Role, join_through: TestExAdmin.UserRole
  8. end
  9.  
  10. <div class="form-group">
  11. <label class="col-sm-2 control-label" for="user_roles">Roles</label>
  12. <div class="col-sm-10">
  13. <input name="user[roles][]" type="hidden" value="">
  14. <div class="checkbox"><label><input type="checkbox" name="user[roles][1]">role1</label></div>
  15. </div>
  16. </div>
  17.  
  18. def changeset(model, params \ %{}) do
  19. model
  20. |> cast(params, @required_fields, @optional_fields)
  21. |> cast_assoc(:noids, required: false)
  22. |> cast_assoc(:products, required: false)
  23. |> cast_assoc(:roles, required: false)
  24. end
  25.  
  26. %{email: "test@example.com", name: "Cory",
  27. products: %{"1481120458618": %{_destroy: "0", price: "13.00",
  28. title: "A product title"}}, roles: %{"1": "on"}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement