Thanks, Craig--I think my example was too terse.  What I'm trying to
do is to pass a block of text to a view which may contain multiple
references to external models, and I'd like to interpolate those
references.

So, for example, if @thing.body = " This is the id of foo: <%= @foo.id
%> and this is its body: <%= @foo.body %> "

If @foo.id = 2 and @foo.body = "Norman", I'd like in the view
whatever.html.erb to have

<%= @thing.body %>

display

This is the id of foo: 2 and this is its body: Norman

Is there a way to do that?  I also tried #{ ... } and am still getting
the literal rather than the interpolation.

Many thanks,
Craig

On Feb 27, 9:30 am, Craig White <[email protected]> wrote:
> On Sat, 2010-02-27 at 07:08 -0800, Dudebot wrote:
> > Is there a way to get a Rails view to interpolate inside <%= %>?
> > E.g. if foo = '<%= bar %>' and bar = '2',
> > to have some variant of <%= foo %> in app/views/whatever/
> > whatever.html.erb display '2' rather than '<%= bar %>'?
>
> ----
> lots of ways... choose whatever is best for the situation...
>
> <%= @foo == 'bar' ? "result 1" : "result 2" %>
>
> or
>
> <% if @foo == 'bar' -%>
>  <%= 'result 1' %>
> <% else -%>
>  <%= 'result 2' %>
> <% end -%>
>
> 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