How to evaluate the string in ruby if the string contains ruby command?
- by Arun
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?