can I store haml code in the database?

86 views
Skip to first unread message

Patrick Aljord

unread,
Oct 3, 2007, 9:06:01 AM10/3/07
to ha...@googlegroups.com
is it possible to store some haml code in the database and then
display it in a view?

Mislav Marohnić

unread,
Oct 3, 2007, 10:08:52 AM10/3/07
to ha...@googlegroups.com
On 10/3/07, Patrick Aljord <pat...@gmail.com> wrote:

is it possible to store some haml code in the database and then
display it in a view?

For sure. You have to render the code manually, though:
  engine = Haml::Engine.new("%p Haml code!")

engine.render
#=> "<p>Haml code!</p>\n"
(copy/paste from http://haml.hamptoncatlin.com/docs/haml)

Jeff Casimir

unread,
Oct 3, 2007, 10:15:14 AM10/3/07
to ha...@googlegroups.com
One of these days when I get my task list down I want to implement a
way to sandbox the HAML rendering so you could allow users to
write/store/render HAML views without risk to the underlying data &
system.

- Jeff

Patrick Aljord

unread,
Oct 3, 2007, 4:18:29 PM10/3/07
to ha...@googlegroups.com
On 10/3/07, Jeff Casimir <je...@casimircreative.com> wrote:
> One of these days when I get my task list down I want to implement a
> way to sandbox the HAML rendering so you could allow users to
> write/store/render HAML views without risk to the underlying data &
> system.
>

what risk are there?

Jeff Casimir

unread,
Oct 3, 2007, 4:24:57 PM10/3/07
to ha...@googlegroups.com
Such as...

%h1 Innocently Printing...
%p
HAML is Great...and now for destruction!
= "KaBLAM!" if User.find(:all).each{|u| u.destroy}

On 10/3/07, Patrick Aljord <pat...@gmail.com> wrote:
>

Mislav Marohnić

unread,
Oct 3, 2007, 5:04:42 PM10/3/07
to ha...@googlegroups.com
On 10/3/07, Jeff Casimir <je...@casimircreative.com> wrote:

Such as...

%h1 Innocently Printing...
%p
  HAML is Great...and now for destruction!
  = "KaBLAM!" if User.find(:all).each{|u| u.destroy}

And even if you don't use Rails, users can -- through Ruby code -- gain access to your system.

If you allow users to edit and store Haml templates on your site, always use suppress_eval when rendering those templates.

Nathan Weizenbaum

unread,
Oct 3, 2007, 8:06:19 PM10/3/07
to ha...@googlegroups.com
Or use the freaky freaky sandbox: http://code.whytheluckystiff.net/sandbox/.

- Nathan

Mislav Marohnić wrote:
> On 10/3/07, *Jeff Casimir* <je...@casimircreative.com

Reply all
Reply to author
Forward
0 new messages