Last active
February 23, 2021 12:42
-
-
Save gathuku/438aa16edb687ddef92d2c67d8d1368a to your computer and use it in GitHub Desktop.
Rails checkbox form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_with(model: user_group, local: true) do |form| %> | |
<% if user_group.errors.any? %> | |
<div id="error_explanation" class="alert alert-danger"> | |
<h5><%= pluralize(user_group.errors.count, "error") %> prohibited this user group from being saved:</h5> | |
<ul> | |
<% user_group.errors.full_messages.each do |message| %> | |
<li><%= message %></li> | |
<% end %> | |
</ul> | |
</div> | |
<% end %> | |
<div class=""> | |
<%= form.hidden_field :account_id, value: current_user&.account&.id %> | |
</div> | |
<div class="form-group"> | |
<%= form.label :name %> | |
<%= form.text_field :name, class: 'form-control' %> | |
</div> | |
<div class="form-group"> | |
<%= form.label :desc %> | |
<%= form.text_field :desc, class: 'form-control' %> | |
</div> | |
<div class="form-group"> | |
<table class="table"> | |
<thead> | |
<th>Resource name</th> | |
<th>Actions</th> | |
</thead> | |
<tbody> | |
<%= form.fields_for :permissions do |form| %> | |
<%= render "permission_fields", form: form %> | |
<% end %> | |
</tbody> | |
</table> | |
</div> | |
<div class="form-group"> | |
<% if user_group.persisted? %> | |
<div class="float-right"> | |
<%= link_to 'Destroy', user_group, method: :delete, class: "text-danger", data: { confirm: 'Are you sure?' } %> | |
</div> | |
<% end %> | |
<%= form.submit class: 'btn btn-primary' %> | |
<% if user_group.persisted? %> | |
<%= link_to "Cancel", user_group, class: "btn btn-link" %> | |
<% else %> | |
<%= link_to "Cancel", user_groups_path, class: "btn btn-link" %> | |
<% end %> | |
</div> | |
<% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<tr> | |
<td> <%= form.text_field :controller_name %> </td> | |
<td> | |
<%= form.fields_for :actions do |field|%> | |
index<%= field.check_box :index %> | |
show<%= field.check_box :show %> | |
<% end %> | |
</td> | |
</tr> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserGroup < ApplicationRecord | |
belongs_to :account | |
has_many :permissions, dependent: :destroy | |
validates :desc, presence: true | |
validates :name, presence: true, uniqueness: true | |
accepts_nested_attributes_for :permissions, allow_destroy: true | |
end |
Author
gathuku
commented
Feb 23, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment