Making a web page with ruby without rails

前端 未结 4 1503
庸人自扰
庸人自扰 2020-12-14 03:38

I´m looking for a way to do simple ruby code without rails. I´m coming from PHP world, and sometimes, I just build a page with a Mysql connection, run a query and show resul

4条回答
  •  伪装坚强ぢ
    2020-12-14 04:33

    This should do the work:

    require 'rubygems'
    gem 'activerecord'; require 'active_record'
    
    class User < ActiveRecord::Base
    
    end
    
    ActiveRecord::Base.establish_connection(
      :adapter => 'mysql',
      :database => 'test',
      :user => 'user',
      :password => 'pass'
    )
    
    User.all.each do |u|
      puts "

    #{u.name} - #{u.age}

    " end

    Before running it you need to install activerecord:

    gem install activerecord
    

提交回复
热议问题