Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to find input class EncryptedInput Error #1341

Open
denys-husiev-perfectial opened this issue May 17, 2021 · 1 comment
Open

Unable to find input class EncryptedInput Error #1341

denys-husiev-perfectial opened this issue May 17, 2021 · 1 comment

Comments

@denys-husiev-perfectial

Hello.
After updating formtastic from 3.1.5 to 4.0.0 I have the following error: Unable to find input class EncryptedInput
It appears for field which is encrypted in ActiveRecord model

form.input :field_name, label: "Field" # raises an error
class MyModel < ActiveRecord::Base
  attribute :field_name, :encrypted
end

It is fixed when I explicitly specify form.input :field_name, label: "Field", as: :string.
As I understand, the error appears because of updated method Formtastic::Helpers::InputHelper#column_for which calls type_for_attribute(instead of column_for_attribute) after update and returns encrypted(instead of string)

P.S. Using formtastic as dependency of ActiveAdmin

@mikz
Copy link
Contributor

mikz commented Jun 1, 2021

Hi,

I think thats intended. Formtastic 4 understands Rails 5+ Attributes API. Formtastic 3 didn't, so it defaulted to strings.

This allows you for example to define an attribute attribute :check, :boolean and be rendered as a checkbox. It is like you'd have a column in database of type encrypted. Formtastic behaves the same for these virtual attributes as for real ones.

This also allows you to define a EncryptedInput that handles your specific input in case it is not just plain string (you want some code editor for example).

Formtastic currently does not support easy type aliases for inputs, but you can always override and adjust this method if you need to do it.

def default_input_type(method, options = {}) # @private
if @object
return :select if reflection_for(method)
return :file if is_file?(method, options)
end
column = column_for(method)
if column && column.type
# Special cases where the column type doesn't map to an input method.
case column.type
when :string
return :password if method.to_s =~ /password/
return :country if method.to_s =~ /country$/
return :time_zone if method.to_s =~ /time_zone/
return :email if method.to_s =~ /email/
return :url if method.to_s =~ /^url$|^website$|_url$/
return :phone if method.to_s =~ /(phone|fax)/
return :search if method.to_s =~ /^search$/
return :color if method.to_s =~ /color/
when :integer
return :select if reflection_for(method)
return :select if enum_for(method)
return :number
when :float, :decimal
return :number
when :datetime, :timestamp
return :datetime_select
when :time
return :time_select
when :date
return :date_select
when :hstore, :json, :jsonb
return :text
when :citext, :inet
return :string
end
# Try look for hints in options hash. Quite common senario: Enum keys stored as string in the database.
return :select if column.type == :string && options.key?(:collection)
# Try 3: Assume the input name will be the same as the column type (e.g. string_input).
return column.type
else
return :select if options.key?(:collection)
return :password if method.to_s =~ /password/
return :string
end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants