我想用rails运行一个简单的MYSQL查询
Select movie-title,movie-director from moving order by rating desc limit 5;
我不想要所有开销创建模型.我只想运行查询.
做这个的最好方式是什么?
我甚至无法连接
这是我的控制器代码
ActiveRecord::Base.establish_connection ({
:adapter => "mysql2",:host => "some-rds.amazon.com",:username => "root",:password => "root",:database => "blah"})
这将产生此错误
的ActiveRecord :: ConnectionNotEstablished
谢谢
最佳答案
movie_title = 'Planet of the Apes'
sql = "SELECT * FROM movies WHERE title = #{ActiveRecord::Base.sanitize(movie_title)}"
ActiveRecord::Base.connection.execute(sql)