I don't want Rails where to escape the results.

Asked 3 months ago, Updated 3 months ago, 4 views

If there is a question mark or a quotation mark in the data retrieved in the where statement in Rails, it will be escaped and


and so on.

When viewing it in view, I solved it by doing .html_safe in the view.
I don't know what to do if I want to use the data I got directly from the processing in the controller (which I wrote to the delayed_job job).

Specifically, I would like to use the retrieved data as a search word using an API, but I would like to use the string before escaping.


@hoge_data.each { | row |

  if row.nil?
    # When data is empty, do nothing for now.
    show ['title']
    row ['title'].class
    show ['title'].html_safe

Both row['title'].html_safe and row['title'] display the same.
row['title'].class is string.

#<NoMethodError: undefined method `bytesize' for nil:NilClass>


Thank you for your cooperation.


2022-09-30 14:16

1 Answers

As far as Rails/ActiveRecord is being used honestly, data imported from the database will not be escaped on its own.

row ['title'] 

When you say that it appears as escaped in , either the data stored in the DB has already been escaped, or it has been intentionally created to do extra escape somewhere.

Also, don't do .html_safe in the dark.

2022-09-30 14:16

If you have any answers or tips

© 2023 OneMinuteCode. All rights reserved.