New to Ruby, new to Rails. I've googled much on this topic, but I don't
think I have enough knowledge to form the correct queries.
I've been given the task of resurrecting an old Rails app that's not
seen the light of day for two years. It seems to rely heavily on
render_component which I am given to understand by various error
messages is now deprecated, unfashionable, and unfit to be seen with on
social occasions.
However, what I haven't found is much on what to do with
render_component code to make it more modern, apart from "Components are
a special-purpose approach that can often be replaced with better use of
partials and filters." Whatever they may be.
Is there anywhere I can go to help me understand what the
render_component calls are doing in this particular instance, and how
best to refactor them?
The render_component was extracted as a plugin, so the documentation
here should explain what render_component is actually doing:
http://github.com/rails/render_component/tree/master
I have provided an example here of a refactoring based on what you
described below:
http://gist.github.com/159227
HTH,
Nicholas
Nicholas Henry wrote:
The render_component was extracted as a plugin, so the documentation
here should explain what render_component is actually doing:
GitHub - rails/render_component: NOTICE: official repository moved to https://github.com/malev/render_component. Components allow you to call other actions for their rendered response while executing another action
I have provided an example here of a refactoring based on what you
described below:
gist:159227 ยท GitHub
HTH,
Nicholas
I've had a go at installing the plugin (just to get the thing to work enough I can see what it does) but that just threw up other errors; however, I think the idea of looking through the docs and code is a good one.
The refactoring looks interesting - I'll see if I can wrap my newbie head around it
Thanks.
Yeah, I wouldn't be surprised if the plugin is not compatible with the
latest versions of rails. It probably isn't being maintained. If you
like the concept of components, you can check out Cells which is an
improved version of rendered_component:
http://github.com/apotonick/cells/tree/master
This is an improved version of the concept. I haven't tried it out
myself, but have been meaning to.
Cheers,
Nicholas
I had to do this with my first few rails apps after it turned out that
render_component had horrible performance. It was kind of a pain
because the first rails books used them in examples and there was no
discussion back then about whether or not it was a good idea.
Anyway...
a render :partial and a render component in a controller could be
replaced by a filter of some sort. That said, it has been a long long
time and I might be a bit off there. At anyrate, I had only really
used them in views and converting them usually involved just making
sure whatever variables they depended on were passed in as locals or
already available as instance variables.
Some specific code examples could allow use to make suggestions about
how to start re-factoring.