How to evaluate the string in ruby if the string contains ruby command?
Posted
by Arun
on Stack Overflow
See other posts from Stack Overflow
or by Arun
Published on 2010-03-12T08:14:17Z
Indexed on
2010/03/12
8:17 UTC
Read the original article
Hit count: 185
In my case,
I was storing the sql query in my database as text. I am showing you one record which is present in my database
Query.all
:id => 1, :sql => "select * from user where id = #{params[:id]}"
str = Query.first
Now 'str' has value "select * from user where id = #{params[:id]}"
Here, I want to parsed the string like If my params[:id] is 1 then
"select * from user where id = 1"
I used eval(str). Is this correct?
© Stack Overflow or respective owner