Coder Social home page Coder Social logo

Comments (12)

ledermann avatar ledermann commented on May 20, 2024

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.

noctivityinc avatar noctivityinc commented on May 20, 2024

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.

ledermann avatar ledermann commented on May 20, 2024

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.

Kriechi avatar Kriechi commented on May 20, 2024

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.

noctivityinc avatar noctivityinc commented on May 20, 2024

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.

ledermann avatar ledermann commented on May 20, 2024

@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.

Kriechi avatar Kriechi commented on May 20, 2024

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.

noctivityinc avatar noctivityinc commented on May 20, 2024

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.

ledermann avatar ledermann commented on May 20, 2024

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.

Kriechi avatar Kriechi commented on May 20, 2024

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.

noctivityinc avatar noctivityinc commented on May 20, 2024

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.

Kriechi avatar Kriechi commented on May 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.