RAILS: edit turns null strings into empty strings

Discussion in 'Ruby' started by Wybo Dekker, Jul 23, 2005.

  1. Wybo Dekker

    Wybo Dekker Guest

    In my mysql database I stored empty strings as NULL's, so that I can test
    fields to be nil.

    (It's shorter, nicer and more logical to test "if field" rather than
    "if field == ''")

    But when I edit a record, all NULL's in char fields are replaced with an
    empty string ('').

    Is there a way to prevent this?
    Or is my idea wrong in the first place?

    --
    Wybo
     
    Wybo Dekker, Jul 23, 2005
    #1
    1. Advertising

  2. Wybo Dekker wrote:
    > In my mysql database I stored empty strings as NULL's, so that I can test
    > fields to be nil.
    >
    > (It's shorter, nicer and more logical to test "if field" rather than
    > "if field == ''")
    >
    > But when I edit a record, all NULL's in char fields are replaced with an
    > empty string ('').
    >
    > Is there a way to prevent this?
    > Or is my idea wrong in the first place?


    I think the most simple and semantic way of going about it would be to
    store empty fields as empty strings and use "if field.empty?" to
    determine whether there's anything there. You should be able to convert
    empty fields to nil in your update method, though, if you want to go
    about it that way.
     
    Charles Steinman, Jul 23, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard
    Replies:
    18
    Views:
    672
    David Dorward
    Oct 21, 2003
  2. Dennis Allison

    interpreting a null pointer as an empty (null string)

    Dennis Allison, Mar 5, 2004, in forum: C Programming
    Replies:
    11
    Views:
    814
    Derk Gwen
    Mar 6, 2004
  3. Col
    Replies:
    1
    Views:
    628
    peter koch
    Apr 21, 2006
  4. S Col
    Replies:
    0
    Views:
    322
    S Col
    Nov 29, 2007
  5. Alp
    Replies:
    0
    Views:
    98
Loading...

Share This Page