Forum: Ruby on Rails sticking an erb block in lambda???

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
stewbawka (Guest)
on 2009-05-05 22:03
(Received via mailing list)
i'm doing some meta stuff and trying to figure out how to stick some
erb html into a proc where i can then feed it to one of many helpers.

if i do something like this:

lamb = lambda do |x|
  <b> <%= x %> </b>
end

i get a syntax error because obviously the block isn't actual code.. i
want to be able to do something like <%= html_helper("something",
&lamb) %>

any ideas?

thanks!

Stuart
Frederick C. (Guest)
on 2009-05-05 22:17
(Received via mailing list)
On May 5, 7:02 pm, stewbawka <removed_email_address@domain.invalid> wrote:
> i'm doing some meta stuff and trying to figure out how to stick some
> erb html into a proc where i can then feed it to one of many helpers.
>
> if i do something like this:
>
> lamb = lambda do |x|
>   <b> <%= x %> </b>
> end

because you're in a ruby file, not an erb file you don't need to be
this complicated:

lamb = lambda do |x|
  "  <b> #{ x } </b> "
end

It's a bit more fiddly if you want to call helpers - (one technique is
to have a magic helper object which includes the various rails helpers
so that you can then do magic_helper.number_to_currency ... and things
like that)

Fred
stewbawka (Guest)
on 2009-05-05 22:17
(Received via mailing list)
nevermind.. i'm an idiot.. it works you just have to end the %>
before the erb block.. duh
This topic is locked and can not be replied to.