Syntax Error in Ruby: unexpected tCONSTANT, expecting keyword_end

1

When creating tables I used camelcase to create columns, but to use Ruby on Rails to generate hash, listing the two tables appears error message

Code:

@testes = Teste.find_by_sql(
 "
 SELECT * FROM  tabelax
 INNER JOIN tabelay on tabelay."Campoy" =  tabelax."Campox"
 "
)
 render json: @testes

Error Message: syntax error, unexpected tCONSTANT, expecting keyword_end

    
asked by anonymous 27.04.2018 / 21:10

1 answer

2

You're repeating the double quotes, Ruby can not tell where your string actually ends.

Change the double quotation marks at the beginning for simple and solve.

@testes = Teste.find_by_sql(
 '
 SELECT * FROM  tabelax
 INNER JOIN tabelay on tabelay."Campoy" =  tabelax."Campox"
 '
)
render json: @testes

If you configure your classes correctly you can do this query without SQL, using only ActiveRecord, for example:

Produto.joins(:vendedor).all
    
28.04.2018 / 16:12