Albert Català
2011-Mar-30 22:03 UTC
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. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter Lee Davis
2011-Mar-30 23:12 UTC
Re: Where do I put code when I share a partial between two controllers
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 On Mar 30, 2011, at 6:03 PM, Albert Català wrote:> 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. > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails- > talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Albert Català
2011-Mar-31 10:50 UTC
Re: Where do I put code when I share a partial between two controllers
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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter Lee Davis
2011-Mar-31 12:08 UTC
Re: Re: Where do I put code when I share a partial between two controllers
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 On Mar 31, 2011, at 6:50 AM, Albert Català wrote:> --> 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"-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.