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 via http://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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
You''re amazing Dan! Thanks so much for your great help!! =) That works absolutely perfectly. Thank you! -- Posted via http://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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---