I need to be able to merge a lot of content for web pages, along with links to other pages taken from a list of categories. The text that goes with each category can be different depending on the context that it''s displayed in. I could do this by having a whole stack of *.html.erb files which hold the static content and access the Rails helpers to pull in stuff from the database and build the links & etc. But that''s a rubbish way to do things because I''d end up with too many *.erb files to manage. I want to keep these little snippets of erb or haml ready texts in the DB where they belong, and pull them out and process them into html when required. But... how do I get access to the rails helpers when I''m inside these little snippets. Basically I need to call render, without the layout, and then grab the result and put that into the final page. Sort of like a partial, expect that it''s not something that can be generalised. But I don''t want render to then disappear off and hand the result back to the caller I want render to give me the result and then I''ll merge it with other bits and then hand the completed page to the caller. Any thoughts? Ta John Small -- 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 -~----------~----~----~----~------~----~------~--~---
John Small wrote:> I need to be able to merge a lot of content for web pages, along with > links to other pages taken from a list of categories. The text that goes > with each category can be different depending on the context that it''s > displayed in. > > I could do this by having a whole stack of *.html.erb files which hold > the static content and access the Rails helpers to pull in stuff from > the database and build the links & etc. But that''s a rubbish way to do > things because I''d end up with too many *.erb files to manage. I want to > keep these little snippets of erb or haml ready texts in the DB where > they belong, and pull them out and process them into html when required. > But... how do I get access to the rails helpers when I''m inside these > little snippets. > > Basically I need to call render, without the layout, and then grab the > result and put that into the final page. Sort of like a partial, expect > that it''s not something that can be generalised. But I don''t want render > to then disappear off and hand the result back to the caller I want > render to give me the result and then I''ll merge it with other bits and > then hand the completed page to the caller. > > Any thoughts? > > TaHa, haaa. Having written out the question made me clearly formulate in my mind what I wanted to do. So now I''ve been able to answer my own question. I just call render_to_string with an inline template. Simple.> > John Small-- 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 -~----------~----~----~----~------~----~------~--~---
RichardOnRails
2008-Dec-20 21:35 UTC
Re: Accessing rails helpers when processing erb snippets
Hi John, Congrats on figuring that out. It sounds like a useful construct for a number of situations. Did you make a small test implementation? If so, could you post a couple of callers and renderers to help newbies see actual code? Thanks in advance, Richard On Dec 20, 4:18 pm, John Small <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> John Small wrote: > > I need to be able to merge a lot of content for web pages, along with > > links to other pages taken from a list of categories. The text that goes > > with each category can be different depending on the context that it''s > > displayed in. > > > I could do this by having a whole stack of *.html.erb files which hold > > the static content and access the Rails helpers to pull in stuff from > > the database and build the links & etc. But that''s a rubbish way to do > > things because I''d end up with too many *.erb files to manage. I want to > > keep these little snippets of erb or haml ready texts in the DB where > > they belong, and pull them out and process them into html when required. > > But... how do I get access to the rails helpers when I''m inside these > > little snippets. > > > Basically I need to call render, without the layout, and then grab the > > result and put that into the final page. Sort of like a partial, expect > > that it''s not something that can be generalised. But I don''t want render > > to then disappear off and hand the result back to the caller I want > > render to give me the result and then I''ll merge it with other bits and > > then hand the completed page to the caller. > > > Any thoughts? > > > Ta > > Ha, haaa. Having written out the question made me clearly formulate in > my mind what I wanted to do. So now I''ve been able to answer my own > question. > > I just call render_to_string with an inline template. Simple. > > > > > John Small > > -- > 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 -~----------~----~----~----~------~----~------~--~---
RichardOnRails wrote:> Hi John, > > Congrats on figuring that out. It sounds like a useful construct for > a number of situations. Did you make a small test implementation? If > so, could you post a couple of callers and renderers to help newbies > see actual code? > > Thanks in advance, > Richard > > On Dec 20, 4:18�pm, John Small <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Well it turned out to be not quite so simple. "render_to_string" isn''t available inside helpers or views, which is where I wanted to use it. But after a while scratching around I realised that inside a view or a helper "render" does exactly what "render_to_string" does inside an ActionController. So I just needed to call render :inline=>MySpecialErbString But I couldn''t get a "<%= yield %>" inside the inline text to yield to a block. That''s a different problem which I''ve got round another way. If I''ve got a moment I''ll come back and look at why I can''t yield inside a call to ActionView#render. So the code is basically <%= render :inline=>my_model.A_field_that_stores_erb_text %> and so on. John Small -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
RichardOnRails
2008-Dec-22 14:15 UTC
Re: Accessing rails helpers when processing erb snippets
Thanks for the additional insight. I''ll try to build an example for my own edification. Best wishes, Richard On Dec 21, 9:55 am, John Small <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> RichardOnRails wrote: > > Hi John, > > > Congrats on figuring that out. It sounds like a useful construct for > > a number of situations. Did you make a small test implementation? If > > so, could you post a couple of callers and renderers to help newbies > > see actual code? > > > Thanks in advance, > > Richard > > > On Dec 20, 4:18 pm, John Small <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > Well it turned out to be not quite so simple. "render_to_string" isn''t > available inside helpers or views, which is where I wanted to use it. > But after a while scratching around I realised that inside a view or a > helper "render" does exactly what "render_to_string" does inside an > ActionController. > > So I just needed to call render :inline=>MySpecialErbString > > But I couldn''t get a "<%= yield %>" inside the inline text to yield to a > block. That''s a different problem which I''ve got round another way. If > I''ve got a moment I''ll come back and look at why I can''t yield inside a > call to ActionView#render. > > So the code is basically > > <%= render :inline=>my_model.A_field_that_stores_erb_text %> and so on. > > John Small > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Seemingly Similar Threads
- rendering a partial inside another using render_to_string and (:formats) in controller
- Simple routing problem
- Conditionally adding a link to a form -- how?
- Rails3: render_to_string of a .html.erb when request is a json request raises MissingTemplate error
- Including another helper