Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- schema "users" do
- field :name, :string
- field :email, :string
- field :active, :boolean, default: true
- has_many :products, TestExAdmin.Product
- has_many :noids, TestExAdmin.Noid
- many_to_many :roles, TestExAdmin.Role, join_through: TestExAdmin.UserRole
- end
- <div class="form-group">
- <label class="col-sm-2 control-label" for="user_roles">Roles</label>
- <div class="col-sm-10">
- <input name="user[roles][]" type="hidden" value="">
- <div class="checkbox"><label><input type="checkbox" name="user[roles][1]">role1</label></div>
- </div>
- </div>
- def changeset(model, params \ %{}) do
- model
- |> cast(params, @required_fields, @optional_fields)
- |> cast_assoc(:noids, required: false)
- |> cast_assoc(:products, required: false)
- |> cast_assoc(:roles, required: false)
- end
- %{email: "test@example.com", name: "Cory",
- products: %{"1481120458618": %{_destroy: "0", price: "13.00",
- title: "A product title"}}, roles: %{"1": "on"}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement