Defining a new translatable_method?

10 views
Skip to first unread message

csk

unread,
Aug 10, 2021, 6:39:04 PMAug 10
to Rodauth
Hello again,

I'm using "auth_class_eval" to define a few validation methods. I want to keep using Rodauth's convention of getting the error string from a "translatable_method". But I tried a few different ways and can't get access to "translatable_method" to use in my own code (inside "auth_class_eval"'s block). Is there a good way to do that?

I'm also wondering if I'm stuffing too much code into the configuration block and if it would be better do define a new feature to keep things cleaner. (I know it would be easy to use "translatable_method" then, for instance.) Any guidance on that?

And, related to the creation of a new feature, (final question, I swear!), the docs say:

> You need to place the external feature file where it can be required via rodauth/features/feature_name

Does that mean I have to create a new file inside Rodauth's gem directory? Is there a way to keep "my" code in my app's directory and still have Rodauth find it?

Thanks again!

Regards,

--
Cassio

Jeremy Evans

unread,
Aug 10, 2021, 6:48:40 PMAug 10
to rod...@googlegroups.com
On Tue, Aug 10, 2021 at 3:39 PM csk <ckosh...@gmail.com> wrote:
Hello again,

I'm using "auth_class_eval" to define a few validation methods. I want to keep using Rodauth's convention of getting the error string from a "translatable_method". But I tried a few different ways and can't get access to "translatable_method" to use in my own code (inside "auth_class_eval"'s block). Is there a good way to do that?

translatable_method is a method in features.  You wouldn't want to call it in a Rodauth configuration block.  If you are using auth_class_eval and defining your own mehods, you should have those methods call #translate with any translatable strings.
 
I'm also wondering if I'm stuffing too much code into the configuration block and if it would be better do define a new feature to keep things cleaner. (I know it would be easy to use "translatable_method" then, for instance.) Any guidance on that?

I would only define a new feature if you plan to use it in another application.
 
And, related to the creation of a new feature, (final question, I swear!), the docs say:

> You need to place the external feature file where it can be required via rodauth/features/feature_name

Does that mean I have to create a new file inside Rodauth's gem directory? Is there a way to keep "my" code in my app's directory and still have Rodauth find it?

No, you can add it anywhere in the Ruby load path.  If you want to have an application specific feature, you could have a lib directory in your application, add a lib/rodauth/features/feature_name.rb file with the feature, and make sure that lib directory is in the Ruby load path.  One way to do this would be:

  $: << 'lib'

Thanks,
Jeremy

csk

unread,
Aug 15, 2021, 7:50:04 PMAug 15
to Rodauth
I thought I had answered this, sorry! Thanks, Jeremy, it all makes sense.

Regards,
Reply all
Reply to author
Forward
0 new messages