Using Rails Migration on different database than standard “production” or “development”

前端 未结 20 1398
借酒劲吻你
借酒劲吻你 2020-11-29 18:18

I have a rails project running that defines the standard production:, :development and :test DB-connections in config/database.yml

In addition I have a quiz_developm

20条回答
  •  北海茫月
    2020-11-29 18:46

    if you want to display the wordpress post to your rails website and you don't want to use mult-magic connection gem. you can use the below code in order to get the data from wordpress blog.

     class Article < ActiveRecord::Base
    
        ActiveRecord::Base.establish_connection(
         :adapter  => "mysql2",
         :host     => "localhost",
         :username => "root",
         :database => "blog"
        )
    
        self.table_name = 'wp_posts'
    
        def self.get_post_data()
            query = "select name from testing"
            tst = connection.select_all(query)
            tst[0].fetch('name')
        end
    end
    

提交回复
热议问题