Rendering EEx from a string

Thanks for the reply both :slight_smile: I wasn’t very clear, my apologies. What I meant was instead of a file template I have a string. Read directly from the DB it had something like.

%section
    %h1= link_to "SOMETHING", "http://whatever.org"

I’ve then converted it into something like

"<section><h1><%= link \"SOMETHING\", \"http://whatever.org\" %></h1></section>"

So now I have to eval this string so I could do something like this I think.

EEx.eval_string("<%= link \"BLAH\", \"BLAH\" %>")

I realise now this is sounding ridiculous because I could just replace link_to with

<a href="BLAH">BLAH</a>

And forget about using the link function, but templates must be rendered in such a way that they have access to those View functions so I guess I’m just trying to understand how this all fits together.

Cheers guys

RobL

1 Like