Rails question: changing individual attribute data

Discussion in 'Ruby' started by Sven Schott, Jan 5, 2005.

  1. Sven Schott

    Sven Schott Guest

    Hi

    I've started the tutorials on rails and I've really enjoyed it so far.
    However, I have hit a bit of a snag. I've looked through the tutorials
    and the API but I couldn't figure out how to do it.

    I'm writing an application to store information on system
    specifications. One of the things I would like it to do, is to not
    delete records but instead 'unlink' them(set the id to 0). I know the
    attributes method allows you to replace all the values but I only want
    to replace the id value. I messed around with it until I didn't get an
    error but I still can't get it to work. Help! Help! Any ideas,
    suggestion, criticisms, abuse; hell, I'll take anything useful at this
    point.

    Here's the code I have so far:



    def destroy
    @system = System.find(@params["id"])
    @system.id = 0
    @system.save

    redirect_to :action => "list"
    end

    I don't know if this code does anything useful. :)

    I am running ruby 1.9.0 (2004-03-09) [powerpc-darwin] on MacOS 10.3.7
    on a Powerbook G4. Rails is installed via gem:

    actionmailer (0.4.0)
    Service layer for easy email delivery and testing.

    actionpack (0.9.5)
    Web-flow and rendering framework putting the VC in MVC.

    activerecord (1.1.0)
    Implements the ActiveRecord pattern for ORM.

    rails (0.8.5)
    Web-application framework with template engine, control-flow layer,
    and ORM.

    rake (0.4.12, 0.4.11)
    Ruby based make-like utility.

    sources (0.0.1)
    This package provides download sources for remote gem installation


    The views are the standard tutorial views. They work fine until I try
    the code above.

    Also, is there a rails book in the works? I would really, really like
    one. I would pay exorbitant amounts of money for it.

    Much obliged,


    Sven Schott

    P.S. Thank you very much to the fine gentleman who wrote rails. Once I
    get the hang of it, I will throw Filemaker out the window.
    Sven Schott, Jan 5, 2005
    #1
    1. Advertising

  2. Sven Schott

    Sven Schott Guest

    Sorry about the noise. I scoured the API docs and found the answer.

    @system['field']="value"

    I didn't know it was just a hash. Nice.

    Sven
    On 05/01/2005, at 3:14 PM, Sven Schott wrote:

    > Hi
    >
    > I've started the tutorials on rails and I've really enjoyed it so far.
    > However, I have hit a bit of a snag. I've looked through the tutorials
    > and the API but I couldn't figure out how to do it.
    >
    > I'm writing an application to store information on system
    > specifications. One of the things I would like it to do, is to not
    > delete records but instead 'unlink' them(set the id to 0). I know the
    > attributes method allows you to replace all the values but I only want
    > to replace the id value. I messed around with it until I didn't get an
    > error but I still can't get it to work. Help! Help! Any ideas,
    > suggestion, criticisms, abuse; hell, I'll take anything useful at this
    > point.
    >
    > Here's the code I have so far:
    >
    >
    >
    > def destroy
    > @system = System.find(@params["id"])
    > @system.id = 0
    > @system.save
    >
    > redirect_to :action => "list"
    > end
    >
    > I don't know if this code does anything useful. :)
    >
    > I am running ruby 1.9.0 (2004-03-09) [powerpc-darwin] on MacOS 10.3.7
    > on a Powerbook G4. Rails is installed via gem:
    >
    > actionmailer (0.4.0)
    > Service layer for easy email delivery and testing.
    >
    > actionpack (0.9.5)
    > Web-flow and rendering framework putting the VC in MVC.
    >
    > activerecord (1.1.0)
    > Implements the ActiveRecord pattern for ORM.
    >
    > rails (0.8.5)
    > Web-application framework with template engine, control-flow layer,
    > and ORM.
    >
    > rake (0.4.12, 0.4.11)
    > Ruby based make-like utility.
    >
    > sources (0.0.1)
    > This package provides download sources for remote gem installation
    >
    >
    > The views are the standard tutorial views. They work fine until I try
    > the code above.
    >
    > Also, is there a rails book in the works? I would really, really like
    > one. I would pay exorbitant amounts of money for it.
    >
    > Much obliged,
    >
    >
    > Sven Schott
    >
    > P.S. Thank you very much to the fine gentleman who wrote rails. Once I
    > get the hang of it, I will throw Filemaker out the window.
    >
    >
    >
    Sven Schott, Jan 6, 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. news frontiernet.net
    Replies:
    6
    Views:
    1,177
    news frontiernet.net
    Dec 5, 2003
  2. whiteboy
    Replies:
    8
    Views:
    307
    Default User
    Sep 22, 2005
  3. owolablo
    Replies:
    7
    Views:
    333
    Mike Wahler
    Dec 3, 2006
  4. Replies:
    1
    Views:
    430
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Jun 3, 2007
  5. Fabien LE LEZ
    Replies:
    7
    Views:
    142
    Fabien LE LEZ
    Jul 12, 2006
Loading...

Share This Page