Forum: Ruby on Rails render_component alternatives

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mike H. (Guest)
on 2007-08-01 23:10
(Received via mailing list)
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" %>
Jeff E. (Guest)
on 2007-08-03 06:42
(Received via mailing list)
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
This topic is locked and can not be replied to.