Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在html内容中执行Ruby代码_Ruby On Rails_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 如何在html内容中执行Ruby代码

Ruby on rails 如何在html内容中执行Ruby代码,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我有存储在表中的html内容。在该内容中,我想传递一些ruby代码 比如说 temp = "<html><head>...</head><body>... <%= @something %> ...</body></html>" temp=“……” 然后在我使用temp.html\u safe或raw temp之后 但是有些东西没有印出来 我该怎么做 请帮帮我这种功能可能会让你陷入危险的境地。如果有人破坏您的

我有存储在表中的html内容。在该内容中,我想传递一些ruby代码

比如说

temp = "<html><head>...</head><body>... <%= @something %> ...</body></html>"
temp=“……”
然后在我使用temp.html\u safe或raw temp之后

但是有些东西没有印出来

我该怎么做


请帮帮我

这种功能可能会让你陷入危险的境地。如果有人破坏您的数据库,编辑该记录中的代码以进行破坏性操作,然后通过您的应用程序执行该代码,该怎么办


您应该考虑使用而不是直接执行ERB。(也看看附带的。)

只要在你的代码中做
@temp=“..{@something}…”“
,然后在你看来
就足够了。

“@something's not working”-不像让你的计算机过热爆炸那样工作,或者不像抛出错误那样工作?{@something}”-不打印@something你能给出一个用例的例子吗?@temp=“{@something}”。然后在我尝试@temp.html\u safe之后,它会打印成“\r\n\r\n\r\n\r\n\\{@form.inspect}\r\n…”。但是你在哪里构建字符串呢?在某种意义上?在控制器中?在助手中?在布局文件夹中-application.html.erb