Hello, I'm new in Rails and much more in MVC, and I'm absolutly lost.
The question is more clearly this:
If I have a partial, than uses a controller/method (called X) for
requery itself via JS, and this partial is viewed in two screens ( two
controllers, menu and sarch). where do you place this code (X), In which
controller and views, and js.rjs?
It doesn't matter all that much. If it has a stronger affinity for one of the controllers, then put it in that controller's view folder, and then in the other spot where you need to reference it, just put the leading /modelname/partialname on the render argument.
Thanks for your response, sorry but my unknows go far away:
I have two entitys:
1- Views or Partial: and I undersant this: render :partial /shred/foo
2- Method/controller (X). now I place this method in
application_controller and the .js.rjs in views/application/X.js.rjs. It
works
But I do that because in "menu" controller and "Maintenance" contoller I
call X, but not as a "redirecto_to" otherwise as a normal call, as if it
was a function, only to initialize variables.
So that, I need to put X method in applicationController, to be seen
from the others controllers (menu and Maintenance).
--> And this is weird, ¿ or not ? the X method is used for two porpuses:
as a response of a browser JS request, and as "function"
And to tho that I put in X:
if request.xhr?
respond_to do |format|
format.js
end
end
I think this is just basic to how Rails works. The controller responds to requests with methods. Those methods may be further decomposed into other methods and variable values, but your statement is true as far as I understand it.