janko / rodauth-rails

Rails integration for Rodauth authentication framework
https://github.com/jeremyevans/rodauth
MIT License
571 stars 40 forks source link

Change the model name #56

Closed resgar closed 3 years ago

resgar commented 3 years ago

Is there a way to rename the model to User instead of Account? I'm building a banking app that has a table called accounts to store users' bank account details. I don't want to change the table name to something else, because it can be misleading to developers.

janko commented 3 years ago

Yes, you can rename the tables and then update the Rodauth configuration to reference new table names:

configure do
  accounts_table :users
  reset_password_table :user_password_reset_keys
  remember_table :user_remember_keys
  # ...
end

To do it for all Rodauth tables, you can use this code:

configure do
  methods.grep(/_table$/) do |table_method|
    public_send(table_method) { super().to_s.sub('account', 'user').to_sym }
  end
end