I want to put a ‘search_box’ text_field in the header of each page.
The search_box is implemented in a controller named ‘users’.
(so Controller_A is calling a component in Controller_B)
When I add this line to my ‘controllers/application.rb’ file, I don’t
understand why I get and ‘undefined method’ error. After all, “class
ApplicationController < ActionController::Base”.
@sbox = render_component_as_string(:controller=>‘users’,
:action=>:search)
My problem is very similar to the the one described in a post to this
list 6
months ago:
http://lists.rubyonrails.org/pipermail/rails/2006-February/016759.html
Nobody ever explained it then. I corresponded with the February poster,
who
points out that it is ‘protected’, and suggests that is why Controller_A
can’t call an Action in Controller_B. But some folks on the Site5
forums, as
well as the book authors (Dave T., ‘Agile Web D. with
Rails’,
Chad F., ‘Rails Recipes’) claim to make cross-controller calls. And
if
cross-controller invocations simply didn’t work, the whole point of
Components would be greatly diminished.
I also read this nice ‘components’ doc
http://manuals.rubyonrails.com/read/chapter/71
…
which leaves a little unclear if both ‘render_component’ and
‘render_component_as_string’ can both be called from either a View or
Controller, but I think the doc is saying that either method can be
called
from either location. So why is it ‘undefined’?