This is what I came up with in the end:

module Helpers
  def method_missing symbol, *args
    unless /^_/!~symbol.to_s
      partial symbol.to_s
    else
      super
    end
  end

  def partial p
    ERB.new(File.read "./crud/views/#{p}.erb").result(binding)
  end
end

I took a look at the route maker, and rather than modify that to have
all controllers inherit a Partials module I just added the above to
the Helpers module.

Design wise it's not perfect. Partials really belong in the Views
module, but with no equivalent to the Mab object when using ERB I
couldn't figure out a way to access partials from the Views module.

Dave

On Tue, Jun 16, 2009 at 3:18 PM, David Susco<[email protected]> wrote:
> So I like using ERB for views and have it implemented something like this:
>
> render t
>  content = ERB.new(File.read "./some_app/views/#{t}.erb").result binding
>  ERB.new(File.read "./some_app/views/layout.erb").result binding
> end
>
> So, effectively I have no Views module. However, I'd like to make use
> of some partials as well. I can make a method for every partial and
> throw it in the Helpers module but that doesn't seem like the right
> road. Does anyone have any suggestions? I tried creating a partial
> method in the main module:
>
> def partial p
>  ERB.new(File.read "./some_app/partials/#{p}.erb").result binding
> end
>
> And then tried overriding missing_method to be fancy:
>
> def missing_method symbol, args*
>  p = symbol.to_s
>  if p[0] == '_'
>    partial p
>  else
>    super
>  end
> end
>
> So I could call partials like this '_some_partial' but as the
> Controller is calling render, I would have to do this in every
> controller class I think. Does anyone have other suggestions?
>
> --
> Dave
>



-- 
Dave
_______________________________________________
Camping-list mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/camping-list

Reply via email to