Comments (12)
The settings are stored via serialized Hash, so type conversion is done out of the scope of this gem. Please, can you give some more information about this issue? Currently I can not reproduce it with Ruby 2.1.1 and rails-settings 2.2.1
from rails-settings.
Just like I mentioned. If I do user.settings(:general).show_pic = true and then try to do if user.settings(:general).show_pic it fails but if I do if user.settings(:general).show_pic == ‘true’ it works. I checked and the data is coming back as a string no matter what in Rails 3.2 Ruby 2.0.0.
Joshua Lippiner
.:t 704.323.5661
.:e [email protected] (mailto:[email protected])
On Monday, April 21, 2014 at 2:53 AM, Georg Ledermann wrote:
The settings are stored via serialized Hash, so type conversion is done out of the scope of this gem. Please, can you give some more information about this issue? Currently I can not reproduce it with Ruby 2.1.1 and rails-settings 2.2.1
—
Reply to this email directly or view it on GitHub (#50 (comment)).
from rails-settings.
A very similar case is already tested, please have look here:
https://github.com/ledermann/rails-settings/blob/master/spec/settings_spec.rb#L21
On Travis, the tests are running fine with Rails 3.2 on Ruby 2.0.0:
https://travis-ci.org/ledermann/rails-settings/jobs/22591526
Currently I have no explanation why it does not work for you. Can you try to build a failing test?
from rails-settings.
The testcase @ledermann mentioned, does not test to the current issue.
Because any string is true
. Only false
and nil
map to the boolean value of FALSE.
Consider a test like this
it "should handle method syntax" do
account.settings(:portal).enabled = true
account.settings(:portal).enabled.should eq(true)
account.settings(:portal).hide = false
account.settings(:portal).hide.should eq(false)
account.settings(:portal).foo = "false"
account.settings(:portal).foo.should eq("false")
account.settings(:portal).bar = "true"
account.settings(:portal).bar.should eq("true")
end
from rails-settings.
I was able to get the tests to pass. I think the issue might be the HTML checkboxes. Even though I have the values set as true and false, its possible it’s saving them as a string “true” and “false” in the database. Im going to need to look to see about converting them when I receive the form.
Thanks,
Joshua Lippiner
.:t 704.323.5661
.:e [email protected] (mailto:[email protected])
On Tuesday, April 22, 2014 at 8:51 AM, Thomas Kriechbaumer wrote:
The testcase @ledermann (https://github.com/ledermann) mentioned, does not test to the current issue.
Because any string is true. Only false and nil map to the boolean value of FALSE.
Consider a test like this
it "should handle method syntax" do account.settings(:portal).enabled = true account.settings(:portal).enabled.should eq(true) account.settings(:portal).hide = false account.settings(:portal).hide.should eq(false) account.settings(:portal).foo = "false" account.settings(:portal).foo.should eq("false") account.settings(:portal).bar = "true" account.settings(:portal).bar.should eq("true") end—
Reply to this email directly or view it on GitHub (#50 (comment)).
from rails-settings.
@Kriechi: IMHO this is not fully correct. "foo".should be_true
is ok. But "foo".should eq(true)
fails. Your additional tests are all running fine, no need to change anything.
@noctivityinc: Ok, it seems that the issue is caused by form params. Editing settings via a form needs some manual conversion.
from rails-settings.
Hmm, I just tried this in my Rails console:
pry(main)> account.settings(:foo).bar = false
false
pry(main)> account.settings(:foo).save
true
pry(main)> account.settings(:foo).bar
"false"
But I would expect the last result to be the boolean value false
, and not the string "false"
from rails-settings.
YES! Thank you. Ok, its not just me. That is what I was seeing as well.
Thoughts?
On Tuesday, April 22, 2014 at 10:03 AM, Thomas Kriechbaumer wrote:
Hmm, I just tried this in my Rails console:
pry(main)> account.settings(:foo).bar = false false pry(main)> account.settings(:foo).save true pry(main)> account.settings(:foo).bar "false"But I would expect the last result to be the boolean value false, and not the string "false"
—
Reply to this email directly or view it on GitHub (#50 (comment)).
from rails-settings.
Strange... It seems that serialization is going wrong, but I can not reproduce it. Can someone build a small demo app to demonstrate the issue?
from rails-settings.
Sorry guys, I revoke my earlier statement.
If one uses the Rails console correctly, everything is working as expected.
FYI: for HTML form params converting I use this:
http://drawingablank.me/blog/ruby-boolean-typecasting.html
from rails-settings.
Oh that’s a sweet little toolkit. Thanks.
Joshua Lippiner
.:t 704.323.5661
.:e [email protected] (mailto:[email protected])
On Tuesday, April 22, 2014 at 1:13 PM, Thomas Kriechbaumer wrote:
Sorry guys, I revoke my earlier statement.
If one uses the Rails console correctly, everything is working as expected.
FYI: for HTML form params converting I use this:
http://drawingablank.me/blog/ruby-boolean-typecasting.html—
Reply to this email directly or view it on GitHub (#50 (comment)).
from rails-settings.
IMHO this issue can be closed.
The main issue of @noctivityinc should be resolved with proper conversion of HTML form params.
from rails-settings.
Related Issues (20)
- Administrate SelectField options being chached
- Unexpected behavior concerning 'default-settings' in class hierarchies (STI)
- I dont get it to work with dynamic settings HOT 4
- Settings keys cannot be a single character
- `default_settings` nested Arrays and Hashes are mutable
- Its throwing error while using the gem with a different table name with same fields as of settings table
- Typo in the md file
- Any way to pass in allowed classes so the YAML.load deserialize things saved before the Active Record update? HOT 3
- undefined method `timestamped_migrations' for ActiveRecord::Base:Class (NoMethodError) HOT 1
- Interest in RSpec matchers? HOT 2
- Migrate older settings in new format
- JSON column for `value`
- Accessing settings values as JSON??? HOT 1
- update settings with devise controller
- Doesnt work with Rails_admin gem HOT 6
- ActiveModel::Serializer::Null with Hash
- Default settings with a nested hash HOT 1
- Silent return of defaults if Rails not initialized HOT 1
- Default settings still working? HOT 3
- Active Admin
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rails-settings.