dcunited001
2012-May-03 05:31 UTC
Loading delegates in Rails View Helpers on to instance objects
Not sure if this should be done, but I''m writing some excel reports in ruby. In the rxls views, i''m finding that i refer to @report all the time. In order to make my life easier i created a bunch of methods in the ReportsHelper for the base ReportsController. But i''m finding that i''m essentially defining delegates that point straight to my @report object. It makes my reports views more readable. I wanted to find some way to load at least some of these methods as delegates. I was thinking about using self.included on the ReportsHelper module and loading them onto the class there. I''m trying to look through ActionPack to see where these are loaded, but no dice. I''m worried about any magic that might be going on. Also, I''m just curious as to how and when these are loaded. Any good places to start? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/aULxrpmyo5IJ. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Piotr Sarnacki
2012-May-03 17:51 UTC
Re: Loading delegates in Rails View Helpers on to instance objects
You could just do: delegate :something, :to => "@report" On Wed, May 2, 2012 at 10:31 PM, dcunited001 <dconner.pro@gmail.com> wrote:> Not sure if this should be done, but I''m writing some excel reports in > ruby. In the rxls views, i''m finding that i refer to @report all the time. > > > In order to make my life easier i created a bunch of methods in the > ReportsHelper for the base ReportsController. But i''m finding that i''m > essentially defining delegates that point straight to my @report object. > It makes my reports views more readable. > > I wanted to find some way to load at least some of these methods as > delegates. I was thinking about using self.included on the ReportsHelper > module and loading them onto the class there. > > I''m trying to look through ActionPack to see where these are loaded, but > no dice. I''m worried about any magic that might be going on. Also, I''m > just curious as to how and when these are loaded. Any good places to start? > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-core/-/aULxrpmyo5IJ. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. >-- Piotr Sarnacki http://piotrsarnacki.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.