You may also want to check out Liquid for a safer way of doing
templates:

http://www.liquidmarkup.org/

Jarin Udom
Robot Mode LLC

On Feb 27, 1:15 pm, Dudebot <[email protected]> wrote:
> Found it.  Use #{}, eval and '"'
>
> e.g. foo = '#{ bar }'
> then eval( '"' + foo + '"' ) will interpolate bar
>
> Freshmeat has a great write-up on templates in Ruby 
> athttp://freshmeat.net/articles/templates-in-ruby, including other
> approaches
>
> Needless to say, this code is *not safe*.  A user can run anything in
> that eval.  In my application, only trusted users have access to
> building templates.
>
> We love Ruby :)
> Craig
>
> On Feb 27, 1:17 pm, Dudebot <[email protected]> wrote:
>
>
>
> > I'm no expert at Rails, Craig, but I've been writing working Rails
> > code for about 8 months now on more than a few projects.  I've read
> > Agile Development more than once, and have over the course of time
> > watched scores of Rails webcasts.
>
> > If you have a solution to my question, I'd appreciate it.  I don't
> > think you understand the question.  I need the user to generate their
> > own templates.  If I was hard coding all the templates for them, this
> > would be cake.
>
> > On Feb 27, 12:47 pm, Craig White <[email protected]> wrote:
>
> > > On Sat, 2010-02-27 at 10:12 -0800, Dudebot wrote:
> > > > Thanks, Colin!  I'd like to give the user the flexibility to make a
> > > > template that interpolates objects within it.  Sort of like a mail
> > > > merge.  The templates are stored as text entries in a database.  The
> > > > idea is, say you have something like this as a text entry in the
> > > > database
>
> > > > Dear Mr. <%= @person.lastname %>,
> > > > We understand that your favorite programming language is <%=
> > > > @person.language %>.
>
> > > > Then, if the user was accessing the person show form for @person 2
> > > > with lastname Smith and language Ruby, it would display
>
> > > > Dear Mr. Smith,
> > > > We understand that your favorite programming language is Ruby.
>
> > > > I am so open to ideas :)  Right now I'm imagining building an XML
> > > > parser, and identifying the fields as tags, then replacing them with
> > > > the appropriate objects, but I was wondering if there was a more
> > > > direct (or better) way.
>
> > > ----
> > > I think you need to start with another rails beginner tutorial because
> > > this is very beginner stuff and easily accomplished just as you said and
> > > without any need for xml parsers or sophisticated methods at all.
>
> > > Craig
>
> > > --
> > > This message has been scanned for viruses and
> > > dangerous content by MailScanner, and is
> > > believed to be clean.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to