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=Hoge.where(neko:nil).order(created_at:DESC).limit(10)
@hoge_data.each { | row |
if row.nil?
# When data is empty, do nothing for now.
else
show ['title']
row ['title'].class
show ['title'].html_safe
item=get_data_from_tako(row['title'])
end
}
Both row['title'].html_safe
and row['title']
display the same.
row['title'].class
is string.
item=get_data_from_tako(row['title'].html_safe)
where
#<NoMethodError: undefined method `bytesize' for nil:NilClass>
returns.
Thank you for your cooperation.
ruby-on-rails
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.
356 I want to change the format (date and time display) of the legend in chronological order.
365 FileNotFoundError in json: What is the difference between these two?
352 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
363 Logging Out with the Application Load Balancer and Authentication Using Cognito
© 2023 OneMinuteCode. All rights reserved.