Default values for settings not appearing on an existing site - am I doing anything wrong?
Added by Enrique Garcia about 14 years ago
Hello there,
I've nearly finished a plugin that allows 'filtering' on the projects/index view, via text and also custom fields.
The admin can decide what custom fields are used as filters on the plugin configuration page, and he's also able to add custom CSS rules that appear on projects/.
I thought - well, let's configure those as settings!
Here's the init.rb part that initializes the settings:
Redmine::Plugin.register :redmine_project_filtering do
# ...
settings({
:partial => 'settings/redmine_project_filtering',
:default => {
'used_fields' => {},
'css' => "
#project_filtering label { display: block; }
... (some more css rules here)
"
}
})
end
My problem is: when I install this plugin on my testing environment (script/plugin install my-git-address, the plugin doesn't have any plugin migrations), if I go to the plugin settings, they are blank (they are also blank on the db, although I expected that, kindof)
Must I do anything else in order to have the settings default to what is written above when they are installed on an existing site, or do they just meant to be used when I do rake redmine:load_default_data?
Replies (3)
RE: Default settings not appearing - Added by luigifab ! over 9 years ago
Same problem... my default setting not appearing in the plugin settings (I have cleared plugin settings in database and restart Redmine).
RE: Default values for settings not appearing on an existing site - am I doing anything wrong? - Added by Alexander Stehlik about 8 years ago
I know this question is quite old but I had the same problem and wanted to provide a solution since this is one of the first results on Google for this topic.
Since the plugin settings are stored serialized we need to provide the default values in a ActionController::Parameters
object:
default_settings = {
:setting_1 => 'Setting 1 value',
:setting_2 => 'Setting 2 value'
...
}
default_settings = ActionController::Parameters.new(default_settings)
...
Redmine::Plugin.register :myplugin do
...
settings :partial => 'settings/my_settings_partial',
:default => default_settings
...
end
I hope this helps.
RE: Default values for settings not appearing on an existing site - am I doing anything wrong? - Added by Tobias Fischer over 7 years ago
I have the same problem, but unfortunately, Alexander's solution does not work for me :-(
The default_settings will not get stored in the database and everytime I try to read them I get nil
as return.