I'd go with something like this:
class Page
def processed_body
body.gsub(/\{\{(.+?)\}\}/) do
snippet = Snippet.find_by_title($1)
snippet ? snippet.body : "could not find snippet: #{$1}"
end
end
end
Then in your view you can use:
@page.processed_body
-Dan Manges
http://www.dcmanges.com/blog
On Sep 20, 3:10 am, Bob Sanders <[EMAIL PROTECTED]>
wrote:
> I'm trying to replicate the Snippet functionality in typical CMSs. I
> have a table called "Pages" and "Snippets", where the latter is inserted
> into the former.
>
> I want the @page.body to replace anything between these tags {{ }} with
> its appropriate snippet title (e.g., {{ Footer }}).
>
> I'm thinking something along the lines of:
>
> <%=h @page.body.gsub("ANYTHING_BETWEEN_{{_}}_TAGS",
> Snippet.find_by_title("APPROPRIATE_SNIPPET_TITLE_HERE").body ) %>
>
> Any ideas?
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---