Where do I put code when I share a partial between two controllers

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?

where can i see an example?

thanks you.

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.

So you have

views   bars     index.html.erb   foos     _foo.html.erb     index.html.erb

and you want to re-use the foo partial to make a list of foos in the bars/index view, you would just do this:

  render :partial => '/foos/foo', :collection => @foos

in your bars index, assuming you had gathered a collection of foos in your bars_controller inside the index method.

Walter

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

thanks again

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.

Walter