Hey All Quick question, what''s the merb equivalent of this: ActionView::Base.new([template_root], assigns, self) in merb? Ive found Merb::Template::Erubis.transform(:file => ''/path/to/file'') But I''ve no idea if thats the correct thing to be calling? It doesn''t ''feel'' right, so im not sure it is? Thanks Tim
Hi Tim- On Jan 3, 2008, at 11:13 AM, Tim Perrett wrote:> Hey All > > Quick question, what''s the merb equivalent of this: > > ActionView::Base.new([template_root], assigns, self) > > in merb? Ive found > > Merb::Template::Erubis.transform(:file => ''/path/to/file'') > > But I''ve no idea if thats the correct thing to be calling? It doesn''t > ''feel'' right, so im not sure it is? > > Thanks > > TimWhat are you trying to do exactly? Are you just trying to render a template directly? The closest thing to what you are trying there would be something like this: template = "#{MERB_VIEW_ROOT}/articles/index.html.erb" engine = Merb::Template.engine_for(template) body = engine.transform(:file => template, :view_context => ViewContext.new(self)) The self in the ViewContext.new(self) is a controller instance so this code would need to go in your controller somewhere. This article might help too: http://www.timocracy.com/articles/2007/12/17/isolated-controller-and-view-testing-in-merb Cheers- - Ezra Zygmuntowicz -- Founder & Software Architect -- ezra at engineyard.com -- EngineYard.com
Hey Ezra I am actually implementing a SMS gem for merb that i want to put onto rubyforge. But I thought that to keep the MVC structure id break out the actual message into a ERB view file. It occurred to me that ActionMailer renders things directly, so I took a look at that which is where I got the idea for rendering the template directly. Perhaps there is a ''more merb'' way of handling the templates? Many thanks Tim On 3 Jan 2008, at 19:50, Ezra Zygmuntowicz wrote:> What are you trying to do exactly? Are you just trying to render a > template directly? The closest thing to what you are trying there > would be something like this: > > template = "#{MERB_VIEW_ROOT}/articles/index.html.erb" > engine = Merb::Template.engine_for(template) > body = engine.transform(:file => template, :view_context => > ViewContext.new(self)) > > The self in the ViewContext.new(self) is a controller instance so > this code would need to go in your controller somewhere. > > This article might help too: > http://www.timocracy.com/articles/2007/12/17/isolated-controller-and-view-testing-in-merb > > Cheers- > > - Ezra Zygmuntowicz
Hey all I ditched all the code I wrote yesterday and started again today implementing something totaly bespoke for merb - needless to say I had much more luck. Everything works now :) I took a look at how the merb mailers work and went from there. I did find it odd there were no generators for the mailers tho? Id be happy to put some together if that would help at all? Cheers Tim