Render_component alternatives


#1

I am not sure if I am the only one, but I really like the idea of
render_component. Too bad it is depricated now. Currently I am using
components so that I can have custom view functions with their own
rhtml files in one folder. That way, I can and drop that folder into
any of my projects and I have that component instantly available. Is
there a better way of doing this?

For example,

foobar.rhtml

Hello <%= @text %> from foobar

foo.rb

class FooController < ActionController::Base
def foo
@text = params[:text]
render :partial => “foobar”
end
end

def foo (text)
render_component :controller => “foo”, :action => “foo”, :params
=> {:text => text}
end

myapp.rhtml (using foo)

<%= foo “hello” %>


#2

how about a helper?

app/views/shared/_foobar.rhtml

Hello <%= text %> from foobar

application_helper.rb

def foo (text)
render :partial => “/shared/foobar”, :locals => {:text => text}
end

myapp.rhtml (using foo)

<%= foo “hello” %>

Note that the partial expects ‘text’, not ‘@text’ sent via locals