Hi, I''ve googled around looking for answers to this simple question, with little success. How do I go about using a view helper from another controller, without putting the helper into application_helper.rb? For example, I would like to render a partial from the Products controller, when I am in a Manufacturer view. I''d like to keep the helper function in products_helper, but haven''t found a way to. Putting everything into the application helper just seems to make it really cluttered, and just about everything ends up there, eventually. Any help much appreciated! -j --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
J Y wrote:> How do I go about using a view helper from another controller, without > putting the helper into application_helper.rb? For example, I would > like to render a partial from the Products controller, when I am in a > Manufacturer view. I''d like to keep the helper function in > products_helper, but haven''t found a way to. Putting everything into > the application helper just seems to make it really cluttered, and > just about everything ends up there, eventually.Put it in app-helper. If you got clutter, make certain you move as much as you can to the Models! But a big issue with Rails is you can''t plug-and-play controllers with their partials. If a partial gets shared into another controller''s view - boom - the shared code has to go up that ol'' stairway to heaven. True MVC ain''t like that! -- Phlip --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Andrew Stone
2008-Apr-25 02:02 UTC
Re: How to reference view helpers from another controller?
> I''d like to keep the helper function in > products_helper, but haven''t found a way to. Putting everything into > the application helper just seems to make it really cluttered, and > just about everything ends up there, eventually. > >Create a module in the lib dir, require that module in your Manufacturers and Products helpers and then include the module in those helpers. e.g. create lib/generic_helper_methods.rb which may look like: module GenericHelperMethods def some_helper_method end end now in products_helper.rb requre "generic_helper_methods" module ProductsHelper include GenericHelperMethods # now some_helper_method is available end -- Andrew Stone --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Gah, that''s what I was afraid of... What a flaw... perhaps there''s some hope of getting this changed in v3? On Apr 24, 9:56 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> J Y wrote: > > How do I go about using a view helper from another controller, without > > putting the helper into application_helper.rb? For example, I would > > like to render a partial from the Products controller, when I am in a > > Manufacturer view. I''d like to keep the helper function in > > products_helper, but haven''t found a way to. Putting everything into > > the application helper just seems to make it really cluttered, and > > just about everything ends up there, eventually. > > Put it in app-helper. > > If you got clutter, make certain you move as much as you can to the Models! > > But a big issue with Rails is you can''t plug-and-play controllers with their > partials. If a partial gets shared into another controller''s view - boom - the > shared code has to go up that ol'' stairway to heaven. > > True MVC ain''t like that! > > -- > Phlip--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
J Y wrote:> Gah, that''s what I was afraid of... What a flaw... perhaps there''s > some hope of getting this changed in v3?If you mean Rails 2, no, because as Andrew Stone pointed out you still have the full power of Ruby''s native class systems at your fingertip. I would still go with pushing things into Models first, though... -- Phlip --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Craig White
2008-Apr-25 02:17 UTC
Re: ****[Rails] Re: How to reference view helpers from another controller?
Hi On Thu, 2008-04-24 at 19:04 -0700, J Y wrote:> Gah, that''s what I was afraid of... What a flaw... perhaps there''s > some hope of getting this changed in v3? > > On Apr 24, 9:56 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > J Y wrote: > > > How do I go about using a view helper from another controller, without > > > putting the helper into application_helper.rb? For example, I would > > > like to render a partial from the Products controller, when I am in a > > > Manufacturer view. I''d like to keep the helper function in > > > products_helper, but haven''t found a way to. Putting everything into > > > the application helper just seems to make it really cluttered, and > > > just about everything ends up there, eventually. > > > > Put it in app-helper. > > > > If you got clutter, make certain you move as much as you can to the Models! > > > > But a big issue with Rails is you can''t plug-and-play controllers with their > > partials. If a partial gets shared into another controller''s view - boom - the > > shared code has to go up that ol'' stairway to heaven. > > > > True MVC ain''t like that!---- you''re obviously not tracking what Phlip is saying here. Rails v3 is not going to abandon MVC You need to figure out which code is Model specific and which is universal and it becomes obvious where the code goes. It''s been working well for Rails developers and it''s not gonna change. Craig --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
David A. Black
2008-Apr-25 02:20 UTC
Re: How to reference view helpers from another controller?
Hi -- On Thu, 24 Apr 2008, J Y wrote:> > Hi, > > I''ve googled around looking for answers to this simple question, with > little success. > > How do I go about using a view helper from another controller, without > putting the helper into application_helper.rb? For example, I would > like to render a partial from the Products controller, when I am in a > Manufacturer view. I''d like to keep the helper function in > products_helper, but haven''t found a way to. Putting everything into > the application helper just seems to make it really cluttered, and > just about everything ends up there, eventually.I''m not sure what''s not working exactly, which probably means I''m misunderstanding the setup. Is this correct? The action is in the manufacturer controller. The view template is in views/manufacturer. The view renders a partial from views/products. That partial calls a method from products_helper.rb. I''d expect that to work fine. Am I describing it wrongly? David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin INTRO TO RAILS June 24-27 London (Skills Matter) See http://www.rubypal.com for details and updates! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
David A. Black
2008-Apr-25 02:29 UTC
Re: How to reference view helpers from another controller?
Hi -- I should add: make sure that you''ve got: helpers :all in application.rb. It should be there by default in a Rails 2.0 app. David On Thu, 24 Apr 2008, David A. Black wrote:> > Hi -- > > On Thu, 24 Apr 2008, J Y wrote: > >> >> Hi, >> >> I''ve googled around looking for answers to this simple question, with >> little success. >> >> How do I go about using a view helper from another controller, without >> putting the helper into application_helper.rb? For example, I would >> like to render a partial from the Products controller, when I am in a >> Manufacturer view. I''d like to keep the helper function in >> products_helper, but haven''t found a way to. Putting everything into >> the application helper just seems to make it really cluttered, and >> just about everything ends up there, eventually. > > I''m not sure what''s not working exactly, which probably means I''m > misunderstanding the setup. Is this correct? > > The action is in the manufacturer controller. > The view template is in views/manufacturer. > The view renders a partial from views/products. > That partial calls a method from products_helper.rb. > > I''d expect that to work fine. Am I describing it wrongly? > > > David > > -- > Rails training from David A. Black and Ruby Power and Light: > INTRO TO RAILS June 9-12 Berlin > ADVANCING WITH RAILS June 16-19 Berlin > INTRO TO RAILS June 24-27 London (Skills Matter) > See http://www.rubypal.com for details and updates! > > >-- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin INTRO TO RAILS June 24-27 London (Skills Matter) See http://www.rubypal.com for details and updates! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Since you can use the helper macro in your controller (there from the early days), neither is Rails, Philp.> > True MVC ain''t like that! > > -- > Phlip--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I see... Sorry for my ignorance - I wasn''t familiar with the ''helper'' keyword, although I had investigated ''include'' and ''require''. This is exactly what I needed to know. Thanks! On Apr 24, 10:29 pm, "David A. Black" <dbl...-0o/XNnkTkwhBDgjK7y7TUQ@public.gmane.org> wrote:> Hi -- > > I should add: make sure that you''ve got: > > helpers :all > > in application.rb. It should be there by default in a Rails 2.0 app. > > David > > > > On Thu, 24 Apr 2008, David A. Black wrote: > > > Hi -- > > > On Thu, 24 Apr 2008, J Y wrote: > > >> Hi, > > >> I''ve googled around looking for answers to this simple question, with > >> little success. > > >> How do I go about using a view helper from another controller, without > >> putting the helper into application_helper.rb? For example, I would > >> like to render a partial from the Products controller, when I am in a > >> Manufacturer view. I''d like to keep the helper function in > >> products_helper, but haven''t found a way to. Putting everything into > >> the application helper just seems to make it really cluttered, and > >> just about everything ends up there, eventually. > > > I''m not sure what''s not working exactly, which probably means I''m > > misunderstanding the setup. Is this correct? > > > The action is in the manufacturer controller. > > The view template is in views/manufacturer. > > The view renders a partial from views/products. > > That partial calls a method from products_helper.rb. > > > I''d expect that to work fine. Am I describing it wrongly? > > > David > > > -- > > Rails training from David A. Black and Ruby Power and Light: > > INTRO TO RAILS June 9-12 Berlin > > ADVANCING WITH RAILS June 16-19 Berlin > > INTRO TO RAILS June 24-27 London (Skills Matter) > > Seehttp://www.rubypal.comfor details and updates! > > -- > Rails training from David A. Black and Ruby Power and Light: > INTRO TO RAILS June 9-12 Berlin > ADVANCING WITH RAILS June 16-19 Berlin > INTRO TO RAILS June 24-27 London (Skills Matter) > Seehttp://www.rubypal.comfor details and updates!--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
David A. Black
2008-Apr-26 01:31 UTC
Re: How to reference view helpers from another controller?
Hi -- On Thu, 24 Apr 2008, Phlip wrote:> > J Y wrote: > >> How do I go about using a view helper from another controller, without >> putting the helper into application_helper.rb? For example, I would >> like to render a partial from the Products controller, when I am in a >> Manufacturer view. I''d like to keep the helper function in >> products_helper, but haven''t found a way to. Putting everything into >> the application helper just seems to make it really cluttered, and >> just about everything ends up there, eventually. > > Put it in app-helper. > > If you got clutter, make certain you move as much as you can to the Models! > > But a big issue with Rails is you can''t plug-and-play controllers with their > partials. If a partial gets shared into another controller''s view - boom - the > shared code has to go up that ol'' stairway to heaven.I think the "helper" method solved J Y''s problem, but it sounds like you''re talking about a different limitation, involving partials. I''m afraid I can''t quite work out what you mean, though (in spite of my being a LZ fan of long standing :-) What exactly is it you can''t do, as between a controller and partials in another view directory? David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin INTRO TO RAILS June 24-27 London (Skills Matter) See http://www.rubypal.com for details and updates! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---