Ruby syntax error: Unexpected tCONSTANT, expecting keyword_end

Asked

Viewed 178 times

1

When creating tables I used camelcase to create columns, but using Ruby on Rails to generate hash, when relating 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

1 answer

2


You are repeating double quotes, Ruby cannot know where your string actually ends.

Change the double quotes at the beginning by simple and will 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
  • Thank you very much vnbrs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.