Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

how to define a save method in ruby for sql databases

def save
    sql = <<-SQL
      INSERT INTO songs (name, album) 
      VALUES (?, ?)
    SQL
 
    DB[:conn].execute(sql, self.name, self.album)
 
    @id = DB[:conn].execute("SELECT last_insert_rowid() FROM songs")[0][0]
 
  end
 
PREVIOUS NEXT
Tagged: #define #save #method #ruby #sql #databases
ADD COMMENT
Topic
Name
3+9 =