chewmanfoo
2010-May-19 18:07 UTC
new controller - how do I access it via other controllers/views?
Guys, I have created a new controller Worker which has a method do_work(inputs), and another method show_work, which has a meaningful associated view (showing the results of the ''work''. So, I need to display the result of show_work in the view of another class called Consumer. So, I need to do a number of things: 1.) setup inputs (a hash) in the Consumer controller. 2.) have the consumer controller show method call Worker''s method do_work(inputs) 3.) have the consumer show view show the results of show_work So, 2.) how do you call Worker.do_work(inputs)? Do I instantiate a Worker class and then call obj_name.do_work(inputs)? 3.) can I make use of the rendering going on in the show_work view in another classes show view? Thanks in advance! -- 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.
Conrad Taylor
2010-May-19 18:20 UTC
Re: new controller - how do I access it via other controllers/views?
On Wed, May 19, 2010 at 11:07 AM, chewmanfoo <chewmanfoo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Guys, > > I have created a new controller Worker which has a method > do_work(inputs), and another method show_work, which has a meaningful > associated view (showing the results of the ''work''. > > So, I need to display the result of show_work in the view of another > class called Consumer. > > So, I need to do a number of things: > > 1.) setup inputs (a hash) in the Consumer controller. > 2.) have the consumer controller show method call Worker''s method > do_work(inputs) > 3.) have the consumer show view show the results of show_work > > So, 2.) how do you call Worker.do_work(inputs)? Do I instantiate a > Worker class and then call obj_name.do_work(inputs)? >You can create a class method on the Worker''s model. For example, def self.do_work( inputs ) ... end> 3.) can I make use of the rendering going on in the show_work view in > another classes show view? > >You can create a shared partial that can be rendered within the show template of the different controllers. Also, you can find alot of information on guides.rubyonrails.org Good luck, -Conrad> Thanks in advance! > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
chewmanfoo
2010-May-19 18:26 UTC
Re: new controller - how do I access it via other controllers/views?
regarding the class method you mentioned, then I can run the Worker.do_work(inputs) method by calling Worker.do_work(inputs)? On May 19, 1:20 pm, Conrad Taylor <conra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Wed, May 19, 2010 at 11:07 AM, chewmanfoo <chewman...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Guys, > > > I have created a new controller Worker which has a method > > do_work(inputs), and another method show_work, which has a meaningful > > associated view (showing the results of the ''work''. > > > So, I need to display the result of show_work in the view of another > > class called Consumer. > > > So, I need to do a number of things: > > > 1.) setup inputs (a hash) in the Consumer controller. > > 2.) have the consumer controller show method call Worker''s method > > do_work(inputs) > > 3.) have the consumer show view show the results of show_work > > > So, 2.) how do you call Worker.do_work(inputs)? Do I instantiate a > > Worker class and then call obj_name.do_work(inputs)? > > You can create a class method on the Worker''s model. For example, > > def self.do_work( inputs ) > ... > end > > > 3.) can I make use of the rendering going on in the show_work view in > > another classes show view? > > You can create a shared partial that can be rendered within the show > template of the different controllers. Also, you can find alot of > information > on guides.rubyonrails.org > > Good luck, > > -Conrad > > > Thanks in advance! > > > -- > > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@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 athttp://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.
Sharagoz
2010-May-19 19:07 UTC
Re: new controller - how do I access it via other controllers/views?
What chewmanfoo is talking about is moving code from the controller into the model. Basically, the consumer controller would call the worker model (if one exists), not the worker controller. When you''re in a situation where you need to run two or more controller actions on the same request then it''s a sign that your implementation isn''t optimal. To call two controller actions you need two requests, which means a redirect after the first one, which means you need some place to store the state between the events. It shouldn''t be necessary. On May 19, 8:26 pm, chewmanfoo <chewman...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> regarding the class method you mentioned, then I can run the > Worker.do_work(inputs) method by calling Worker.do_work(inputs)? > > On May 19, 1:20 pm, Conrad Taylor <conra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On Wed, May 19, 2010 at 11:07 AM, chewmanfoo <chewman...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Guys, > > > > I have created a new controller Worker which has a method > > > do_work(inputs), and another method show_work, which has a meaningful > > > associated view (showing the results of the ''work''. > > > > So, I need to display the result of show_work in the view of another > > > class called Consumer. > > > > So, I need to do a number of things: > > > > 1.) setup inputs (a hash) in the Consumer controller. > > > 2.) have the consumer controller show method call Worker''s method > > > do_work(inputs) > > > 3.) have the consumer show view show the results of show_work > > > > So, 2.) how do you call Worker.do_work(inputs)? Do I instantiate a > > > Worker class and then call obj_name.do_work(inputs)? > > > You can create a class method on the Worker''s model. For example, > > > def self.do_work( inputs ) > > ... > > end > > > > 3.) can I make use of the rendering going on in the show_work view in > > > another classes show view? > > > You can create a shared partial that can be rendered within the show > > template of the different controllers. Also, you can find alot of > > information > > on guides.rubyonrails.org > > > Good luck, > > > -Conrad > > > > Thanks in advance! > > > > -- > > > 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-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://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 athttp://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.