views:

189

answers:

1

I want to scan my erb files looking for specific custom HTML tags (I have done this part) and then before rendering, intercept these tags and replace their html output. I can't find any info relating to this sort of activity in RAILS. Maybe I am not looking in the right place.

A: 

Hey,

maybe you could do sth like:

class PostsController < ApplicationController
  acts_as_special

  def show
    @post = Post.find(params[:id])
    respond_to do |format|
      format.html { my_renderer }
    end
  end
end

and write a plugin or sth:

# Module to Extend a given Controller with the acts_as_special methods

module MyRenderer
  def self.included(base)
    base.extend(ClassMethods)
  end

  module ClassMethods

    def acts_as_special
      include MyRenderer::InstanceMethods
    end
  end

  module InstanceMethods
    def my_renderer
      .. do sth with the code ....
      render :template => ...
    end
  end
end


ActionController::Base.class_eval do
  include MyRenderer
end

well you dont need to write a plugin, you yust have to make "your" render method available for the controller.

if you have a different/better method, please let me know!

kalle