Using Insert statement in active record?

Discussion in 'Ruby' started by Anukul Singhal, Jul 19, 2008.

  1. Hi,

    I know this would be a simple solution to provide for any one of you. I
    am new to active record and this is what I have currently done:

    require 'rubygems'
    require 'active_record'

    puts "connecting to db...."

    ActiveRecord::Base.establish_connection(
    :adapter => "mysql",
    :host => "localhost",
    # :username => "myuser",
    :password => "schumi58",
    :database => "test"
    )

    puts "connection established"

    ActiveRecord::Schema.define do

    drop_table:)testTable)

    create_table:)testTable) do |t|
    t.column :name, :string
    end
    end

    I am also referring to Active Record's rdoc but am not able to make out
    how to use the insert statement in the above code. Can anyone help me in
    using INSERT statement in my code above?

    Thanks,
    Anukul
    --
    Posted via http://www.ruby-forum.com/.
    Anukul Singhal, Jul 19, 2008
    #1
    1. Advertising

  2. Anukul Singhal

    Roger Pack Guest

    Anukul Singhal wrote:

    >
    > I am also referring to Active Record's rdoc but am not able to make out
    > how to use the insert statement in the above code. Can anyone help me in
    > using INSERT statement in my code above?
    >
    > Thanks,
    > Anukul


    Maybe post to the rails group?
    =R
    --
    Posted via http://www.ruby-forum.com/.
    Roger Pack, Jul 20, 2008
    #2
    1. Advertising

  3. Anukul Singhal

    Martin Boese Guest

    Try:

    class TestTable < ActiveRecord::Base
    set_table_name 'testTable'
    end

    TestTable.new:)name=>'stuff').save


    On Saturday 19 July 2008 21:55:53 Anukul Singhal wrote:
    > Hi,
    >
    > I know this would be a simple solution to provide for any one of you. I
    > am new to active record and this is what I have currently done:
    >
    > require 'rubygems'
    > require 'active_record'
    >
    > puts "connecting to db...."
    >
    > ActiveRecord::Base.establish_connection(
    >
    > :adapter => "mysql",
    > :host => "localhost",
    >
    > # :username => "myuser",
    >
    > :password => "schumi58",
    > :database => "test"
    >
    > )
    >
    > puts "connection established"
    >
    > ActiveRecord::Schema.define do
    >
    > drop_table:)testTable)
    >
    > create_table:)testTable) do |t|
    > t.column :name, :string
    > end
    > end
    >
    > I am also referring to Active Record's rdoc but am not able to make out
    > how to use the insert statement in the above code. Can anyone help me in
    > using INSERT statement in my code above?
    >
    > Thanks,
    > Anukul
    Martin Boese, Jul 20, 2008
    #3
    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. MRW
    Replies:
    0
    Views:
    366
  2. Frits van Soldt

    How to insert a new record in detailsview when there are no record

    Frits van Soldt, Nov 16, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    725
    Frits van Soldt
    Nov 17, 2005
  3. J. Muenchbourg
    Replies:
    3
    Views:
    233
    Aaron Bertrand - MVP
    Sep 30, 2003
  4. Guest
    Replies:
    1
    Views:
    244
    Alex G
    Jan 9, 2004
  5. John Honovich

    Active Record Invalid Statement

    John Honovich, Mar 23, 2008, in forum: Ruby
    Replies:
    1
    Views:
    98
    Arlen Cuss
    Mar 23, 2008
Loading...

Share This Page