Replies: 4 comments 9 replies
-
Hey afuno! Thank you for bringing this up. I don’t mind adding I18n, but until now I didn’t have the need for it. The way I currently handle I18n is something like this: class Pay < Actor
input :amount
def call
if error?
fail!(error: I18n.t("pay.errors.payment_processor_failure"))
end
# …
end
private
def error?
true
end
end What kind of syntax or need did you have in mind? |
Beta Was this translation helpful? Give feedback.
-
In addition to what I wrote above, I want to consider one example, which I consider a vulnerability. This is the code from the README: input :user,
must: {
be_an_admin: -> user { user.admin? }
} If it fails, then the error text will look like this: "Input #{key} must #{name} but was #{value.inspect}" That is, all the data of the record will be displayed in the error text. This is very bad. If use It seems to me that the presence of I18n in your gem is very necessary. |
Beta Was this translation helpful? Give feedback.
-
What do you think about such an implementation as an alternative? I mean an implementation that keeps the current version and also supports a more advanced one? input :user,
type: User,
allow_nil: false,
# must: {
# be_admin: ->(user) { user.admin? }
# }
must: {
be_admin: {
call: ->(user) { user.admin? }, # Alternative names for `call`: state, condition
message: (lambda do |input_key, must_key, user| # Here are all the values that are described in the current error texts
# "Input #{input_key} must #{must_key} but was #{user.inspect}" # <= current error text
"Input #{input_key} must #{must_key} but was #{user.kind}" # <= do not show an object with sensitive data
# or simply
# "The user must be an admin" # <= any other text at the request of the developer inside the Rails application
end)
}
} It seems to me that this is easier to implement than the I18n integration. In such a case, I18n becomes optional and will be decided within the Rails application. |
Beta Was this translation helpful? Give feedback.
-
Added to v3.3.0 🎉 |
Beta Was this translation helpful? Give feedback.
-
Your gem is a good solution with a fresh perspective on some things. Thank you.
But I18n support for adding translations for different languages is very much lacking. Also, there is a lack of specifying custom text bypassing I18n. In general, this is how the ActiveModel works.
Can you please tell me if you plan to add support for this in the near future?
Beta Was this translation helpful? Give feedback.
All reactions