Hi all. I have something that''s like a helper and like a partial but not quite either. Instead of typing this: <% if (page = ComatosePage.find_by_path("general/explore")) || current_user.admin? %> <div class="quarter"> <div class="module"> <%= page ? page.to_html : "Comatose article ''general/explore'' not found" %> </div> </div> <% end %> I want to do something like this but i can''t get my head around quite how to set it up: <% comatose_article("general/explore") do |article| %> <div class="quarter"> <div class="module"> <%= article %> </div> </div> <% end %> This is so i can use the same pattern of "if the article''s not there show nothing at all, unless the current user is an admin in which case show the ''missing article'' message", but with arbitrary html wrapped around the actual article (in this case the arbitrary html is the quarter and module divs) grateful for any advice - max -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jul 26, 1:55 pm, Max Williams <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > This is so i can use the same pattern of "if the article''s not there > show nothing at all, unless the current user is an admin in which case > show the ''missing article'' message", but with arbitrary html wrapped > around the actual article (in this case the arbitrary html is the > quarter and module divs) >A helper that yields is what you want. Have a look at the concat & capture helpers too. Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Frederick Cheung wrote:> On Jul 26, 1:55�pm, Max Williams <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> >> This is so i can use the same pattern of "if the article''s not there >> show nothing at all, unless the current user is an admin in which case >> show the ''missing article'' message", but with arbitrary html wrapped >> around the actual article (in this case the arbitrary html is the >> quarter and module divs) >> > > A helper that yields is what you want. Have a look at the concat & > capture helpers too. > > FredThanks for the prod Fred. I knew it would be something using yield but couldn''t quite get my head around it. It turned out to be simpler than i thought: def comatose_article(path) if page = ComatosePage.find_by_path(path) yield page.to_html elsif current_user.admin? yield "Couldn''t find ''#{path}'' page" end end Cheers, max -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.