String not matched #31

Closed
steventen opened this Issue Mar 14, 2013 · 4 comments

Projects

None yet

2 participants

@steventen

Hi,

I used settings in my User model. But when I try to set variable, it always raise IndexError: string not matched, and gives follow information:

from /Users/stevenyue/.rvm/gems/ruby-1.9.3-p392@global/gems/ledermann-rails-settings-2.0.1/lib/rails-settings/setting_object.rb:59:in `[]='
from /Users/stevenyue/.rvm/gems/ruby-1.9.3-p392@global/gems/ledermann-rails-settings-2.0.1/lib/rails-settings/setting_object.rb:59:in `_set_value'
from /Users/stevenyue/.rvm/gems/ruby-1.9.3-p392@global/gems/ledermann-rails-settings-2.0.1/lib/rails-settings/setting_object.rb:32:in `method_missing'
from (irb):3
from /Users/stevenyue/.rvm/gems/ruby-1.9.3-p392@global/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
from /Users/stevenyue/.rvm/gems/ruby-1.9.3-p392@global/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
from /Users/stevenyue/.rvm/gems/ruby-1.9.3-p392@global/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

I followed exactly the same installation and settings in the instructions.

has_settings do |s|
s.key :dashboard, :defaults => { :theme => 'blue', :view => 'monthly', :filter => false }
s.key :calendar,  :defaults => { :scope => 'company'}
end

I can get the value by using

user = User.find(1)
user.settings(:dashboard).theme

But I can't set value using either way you provided.

I'm using rails 3.2.11, and the User model is generated by devise

Thanks

@ledermann
Owner

The error message IndexError: string not matched happens when a string is accessed as a Hash. So it seems something went wrong with the string serialization to Hash in SettingObject. FYI: The attribute value is stored as a text column in the database and contains the YAML representation of the Hash.

Please, can you give some more hints to reproduce the bug? Can you create a failing test?

@steventen

Hi @ledermann

I just did a test. Basically, if you just change the database adapter from sqlite3 to mysql2 under spec_helper, and run queries_spec.rb, and it will give you the IndexError: string not matched

@ledermann ledermann was assigned Mar 15, 2013
@ledermann
Owner

Thanks, I will look into it.

@ledermann ledermann closed this in 891c9ff Mar 16, 2013
@ledermann
Owner

@steventen Sorry, the database schema must not define a default for the value column. Please remove the default and it should work on MySQL. I will add MySQL testing on Travis soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment