class DraftGenerators::DeviseCustomizationService
Public Class Methods
new(attributes)
click to toggle source
# File lib/devise_customization_service.rb, line 5 def initialize(attributes) @attributes = attributes end
Public Instance Methods
column_names()
click to toggle source
# File lib/devise_customization_service.rb, line 73 def column_names columns.map(&:name) end
column_names_string()
click to toggle source
# File lib/devise_customization_service.rb, line 77 def column_names_string ":" + column_names.join(", :").to_s end
columns()
click to toggle source
# File lib/devise_customization_service.rb, line 85 def columns @_columns ||= eligible_attributes end
eligible_attributes()
click to toggle source
# File lib/devise_customization_service.rb, line 89 def eligible_attributes @attributes.reject do |attribute| %w(id created_at updated_at email password).include?(attribute.name) end end
form_fields_to_add()
click to toggle source
# File lib/devise_customization_service.rb, line 9 def form_fields_to_add form_fields = "" columns.each do |column| form_fields += input_field_block(column) end form_fields end
input_field_block(column)
click to toggle source
# File lib/devise_customization_service.rb, line 17 def input_field_block(column) column_name = column.name %{ <!-- Devise Input for #{column_name} start --> <div class="form-group"> <% #{column_name}_was_invalid = resource.errors.include?(:#{column_name}) %> <% #{column_name}_class = "form-control" %> <% if was_validated %> <% if #{column_name}_was_invalid %> <% #{column_name}_class << " is-invalid" %> <% else %> <% #{column_name}_class << " is-valid" %> <% end %> <% end %> <%= f.label :#{column_name} %> #{DraftGenerators::RailsTagService.input_tag(column)} <% if #{column_name}_was_invalid %> <% resource.errors.full_messages_for(:#{column_name}).each do |message| %> <div class="invalid-feedback d-flex"> <%= message %> </div> <% end %> <% end %> </div> <!-- Devise Input for #{column_name} end --> } end
protect_from_forgery_code()
click to toggle source
# File lib/devise_customization_service.rb, line 81 def protect_from_forgery_code "protect_from_forgery with: :exception" end
security_field_block()
click to toggle source
# File lib/devise_customization_service.rb, line 50 def security_field_block return "" if eligible_attributes.empty? " before_action :configure_permitted_parameters, if: :devise_controller? protected def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, :keys => [#{column_names_string}]) devise_parameter_sanitizer.permit(:account_update, :keys => [#{column_names_string}]) end" end