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

Silent return of defaults if Rails not initialized #93

Closed
one-more-alex opened this issue Nov 24, 2018 · 1 comment
Closed

Silent return of defaults if Rails not initialized #93

one-more-alex opened this issue Nov 24, 2018 · 1 comment

Comments

@one-more-alex
Copy link

Looks like here is some mistake.
Suppose I have setting "allow_anonymous" = false in database, but true in defaults.
Then in initializes scripts will have access allowed instead of desired to be forbidden.
Initializes may require settings to start Rails (setup routes, for example).

Here are two options:

  • finish with exception if setting requested before Rails initialized;
  • do the best for get setting even if Rails not completely initialized yet (hooks or whatever).

Sorry to say, but silent return of default values from file instead of database is definitely mess.

I prefer to have second solution like this:

      def rails_initialized?
        return true if Rails.application && Rails.application.initialized?
        return true if try(:consider_initialized?)
        raise "Can't get values before initialization of Rails or #{self.name}.consider_initialized? successful return"
      end

# Also remove conditional returning of defaults if not rails_initialized?
# End even better to convert it to some private method like .ensure_initialized! 

Any case this situation should be highlighted in Readme.
What do you think? Need to apply such a patch?

@one-more-alex
Copy link
Author

Oh... Sorry. This was addressed to another branch: huacnlee/rails-settings-cached#152

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

1 participant