heartcombo / simple_form

Forms made easy for Rails! It's tied to a simple DSL, with no opinion on markup.
http://blog.plataformatec.com.br/tag/simple_form
MIT License
8.21k stars 1.31k forks source link

Auto reload configuration #1818

Closed jclusso closed 3 months ago

jclusso commented 1 year ago

When developing with Simple Form + Tailwind, I've found it extremely painful that you have to restart your server between every adjustment to the configuration. I was wondering if there is any reason we don't have some sort of auto reloading in development?

btrewern commented 11 months ago

This is not a simple_form thing, it's a Rails thing. Any time you change a file in config/initializers/ you have to restart rails.

There may be a way e.g. add the following to the top of your controller:

SimpleForm.setup do |config|
      config.button_class = 'btn btn-info'
end

This should autoload and then you can move this to your initializer when you have finished any changes.

jclusso commented 11 months ago

I was thinking something like this could be implemented.

borama commented 10 months ago

I unfortunately don't think it is possible. I tried to play with the options in the Rails guide but I think it actually doesn't apply here. The problem seems to be that code in the Rails initializers does not get reloaded and none of the options make it reloadable. To me the most promising was the to_prepare block but this also is a callback that allows just a (static / not reloaded) code in the initializer to configure some other reloadable code.

Without moving the configuration to some other place that would get reloaded, this seems not feasible.

nashby commented 3 months ago

Yeah, it might be inconvenient when you write your wrapper configuration (but @btrewern proposed a good alternative for this case, also you could probably look into something like https://avohq.io/blog/auto-reload-rails-initializers-and-other-files-in-development). But when wrapper configuration part if done you rarely need to update your SimpleForm config.