I have an admin form, and I would like to know how can grab the value in my models to puts in my form.ex = Checkbox1 = "cat", Checkbox2 = "dog". (and save that in DB when submitting)
Firstly I have had a new column in my Admin DB : t.string "admin_types"
Here my form admin :
<div class="field">
<label>Email :</label>
<div class="<%=@admin.errors[:email].empty? ? 'field' : 'field error'%>">
<%= f.email_field :email, autofocus: true %>
</div>
</div><br>
<div class="field">
<label>Name :</label>
<div class="<%=@admin.errors[:name].empty? ? 'field' : 'field error'%>">
<%= f.text_field :name %>
</div>
</div><br>
<div class="field">
<label>Password :</label>
<div class="<%=@admin.errors[:password].empty? ? 'field' : 'field error'%>">
<%= f.password_field :password %>
</div>
</div><br>
<!-- ACCOUNT TYPE ADMIN -->
<label>Account Type?</label><br>
<div class="inline fields">
<div class="field">
<div class="ui radio checkbox">
<input type="radio" name="frequency" checked="checked">
<label></label>
</div>
</div>
<div class="field">
<div class="ui radio checkbox">
<input type="radio" name="frequency">
<label>Admin</label>
</div>
</div>
</div>
<div class="inline fields">
<div class="field">
<div class="ui radio checkbox">
<input type="radio" name="frequency">
<label>User</label>
</div>
</div>
<div class="field">
<div class="ui radio checkbox">
<input type="radio" name="frequency">
<label>Moderator</label>
</div>
</div>
</div><br>
And now my models admin:
class Admin < ApplicationRecord
after_initialize :set_default_role, :if => :new_record?
admin_types = [:admin, :user, :superuser, :moderator]
def set_default_role
self.admin_types ||= :user
end
end
When I create a user, it is automatically created with the role "user" ... everything is good on this side. On the other hand I would like to have some advice to know how registered the values of the form in database.
Thanks.
Aucun commentaire:
Enregistrer un commentaire