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/

4 Responses to “Settings Plugin updated”

  1. sclaret Says:

    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/?

  2. sclaret Says:

    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

  3. Alex Wayne Says:

    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.

  4. sclaret Says:

    It looks like it’s fixed.

    Thanks for the quick fix!

Leave a Reply