Settings Plugin updated
March 3rd, 2006
This information is now old. A new version of the plugin can be found here with lots of instructions and examples.
I have added a migration generator to the settings plugin. Now all you need to get running with the plugin are three commands:
ruby script/plugin install --force http://beautifulpixel.textdriven.com/svn/plugins/settings/
ruby script/generate settings_migration
rake migrate
The migration is created for you, nice and easy like.
To update, just use: ruby script/plugin install --force http://beautifulpixel.textdriven.com/svn/plugins/settings/
June 28th, 2007 at 11:05 PM
I believe the plugin is broken in Rails 1.1. When you have it update an existing setting, it simply adds anhttp://beautifulpixel.textdriven.com/articles/2006/03/03/settings-plugin-updatedother recordwith the same var value as the old one into the settings table. Is this a bug or the intended behavior/?
June 28th, 2007 at 11:05 PM
I’m pretty sure this is a nasty little bug. The problem is that when you call Settings.mysetting = “sameasoldvalue”, if you are setting mysetting to the same value as it currently holds, then update_all in def self.[]=(var_name, value) returns 0 because 0 rows are updated. Since the first condition in:
if (update_all([‘value = ?’,value], [‘var = ?’,var_name]) > 0) || create(:var => var_name, :value => value)
evaluates to false, the plugin continues on to create another setting with the same name as the already existing setting. The result is that if you try to update a setting to the same value that it currently holds, you end up with duplicates of the same setting.
Here’s a simple fix, add validates_uniqueness_of :var to class Settings < ActiveRecord::Base
June 28th, 2007 at 11:05 PM
Sorry about that, new version posted on the svn repository. It should solve your problems. If its still broken in anyway please let me know.
June 28th, 2007 at 11:05 PM
It looks like it’s fixed.
Thanks for the quick fix!