Created
April 1, 2020 16:27
-
-
Save minimul/6b67cb5df611340828c7d74078c0b2e0 to your computer and use it in GitHub Desktop.
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 Account < ApplicationRecord | |
# ...... | |
validates :name, presence: true, uniqueness: { case_sensitive: false } validates :name, presence: true, uniqueness: { case_sensitive: false } | |
def create(user:) | |
account_groups.create(user: user) | |
account_owners.create(user: user) | |
end | |
# ..... | |
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
<%= render 'devise/shared/form_shell', captured: capture { %> | |
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), wrapper: :vertical_form) do |f| %> | |
<%= f.input :email, autocomplete: "email", required: true, autofocus: true %> | |
<%= f.input :account_name, label: 'Account Name', placeholder: 'Name of your organization' %> | |
<div class="mt-6"> | |
<%= f.input :password, autocomplete: "new-password" %> | |
<% if @minimum_password_length %> | |
<em>(<%= @minimum_password_length %> characters minimum)</em> | |
<% end %><br /> | |
</div> | |
<div class="mt-6"> | |
<span class="block w-full rounded-md shadow-sm"> | |
<%= f.submit "Sign up", class: tw_full_width_button %> | |
<%= recaptcha_execute('signup') if Rails.env.production? %> | |
</span> | |
</div> | |
<% end %> | |
<% } # capture %> |
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 Users::RegistrationsController < DeviseInvitable::RegistrationsController | |
before_action :configure_sign_up_params, only: [:create, :update] | |
def update | |
user = build_resource(sign_up_params) | |
if user.valid? | |
super | |
else | |
render 'edit' | |
end | |
end | |
def create | |
render 'new' and return if sign_up_captcha_failed? | |
user, account = prepare_resources | |
if user.valid? && account.valid? | |
account.save! | |
super do |res| | |
account.create(user: res) | |
end | |
first_time_user! if resource.persisted? | |
else | |
user.errors.add(:account_name, account.errors[:name].join(',')) unless account.valid? | |
resource.account_name = params[:user][:account_name] | |
render 'new' | |
end | |
end | |
## .... | |
protected | |
def configure_sign_up_params | |
devise_parameter_sanitizer.permit(:sign_up, keys: [:account_name]) | |
end | |
## ..... | |
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
# Use this setup block to configure all options available in SimpleForm. | |
require_relative '../../app/helpers/tailwind_helper' | |
SimpleForm.setup do |config| | |
config.error_notification_class = 'alert alert-danger' | |
config.button_class = 'btn btn-default' | |
config.boolean_label_class = nil | |
include TailwindHelper | |
config.wrappers :vertical_form, tag: 'div', class: "mt-6", error_class: 'border-red-400 border-dashed' do |b| | |
b.use :html5 | |
b.use :placeholder | |
b.optional :maxlength | |
b.optional :pattern | |
b.optional :min_max | |
b.optional :readonly | |
b.use :label, class: tw_label | |
b.wrapper tag: 'div', class: "mt-1 rounded-md shadow-sm" do |i| | |
i.use :input, class: tw_field | |
i.use :error, wrap_with: { tag: 'span', class: 'p-1 bg-red-200' } | |
i.use :hint, wrap_with: { tag: 'p', class: 'p-1 bg-orange-400' } | |
end | |
end | |
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
class User < ApplicationRecord | |
# ..... | |
attribute :account_name, :string # only used for the sign up form | |
# .... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment