Search code examples
mysqlruby-on-railsdynamic-sqlfind-by-sql

Rails Dynamic SQL with variables: undefined method find_by_SQL


I have a complex SQL statement that crosses several tables. I wish to pass variables into this statement dynamically and return the data in a JSON format. Ihave tested and know the query works in PHPMyAdmin and have placed it within the manSearch method in my requests class. At present, the below query simply remarks: undefined method find_by_SQL. I know from documentation that the fin_by_SQl does exist in my version 4.0.1.

How can I make this work?

def mainSearch

    @results = Campaign.find_by_SQL("CREATE TEMPORARY TABLE ...)

    respond_to do |format|
        format.html
        format.json { render json: @results }
    end     
end

Solution

  • It's find_by_sql not find_by_SQL.