Is it possible to include module methods as controller actions and use them? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 21 Jul 2008, at 15:16, blackflash wrote:> > Is it possible to include module methods as controller actions and use > them?Yes. Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jul 21, 4:27 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 21 Jul 2008, at 15:16, blackflash wrote: > > > > > Is it possible to include module methods as controller actions and use > > them? > > Yes. > > FredHow? :) I''ve tried something like this: module ControllerPeople def index puts ''index action'' render :text => ''OK'' end def self.included(base) base.send :helper_method, :index end end class PeopleController < ActionController::Base include ControllerPeople end but, I get no method error ''index'' in PeopleController. Thanks, Dalibor --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 22 Jul 2008, at 13:12, blackflash wrote:> > >> >> That''s odd. I''ve done exactly that (but without the self included >> method - you don''t need that) and it worked fine. >> >> Fred > > Yup, it works that way. But the problem is when I use before_filter in > the controller to decide what module to be included. >That''s doesn''t sound like a great idea - the modules that are included in the controller won''t magically go away at the end of the request (except in development mode)> Is there any solution for this or maybe any design pattern for > polymorphic controllers (that are generated dynamically depending on > some values in post data)?I''ve got the feeling you''re overthinking things. What''s wrong with def some_action if foo bar else baz end end or just redirect the user to a different controller depending on the post data. Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jul 22, 9:19 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''ve got the feeling you''re overthinking things. What''s wrong with > > def some_action > if foo > bar > else > baz > end > end > > or just redirect the user to a differentcontrollerdepending on the > post data. > > FredRedirect would not work since I''m actually writing an API. And the problem with the above code is that it''s kind of modularity programming. I should implement a versioning system for API (depending of the parameter in the request xml data, i.e. api_versions=''2'', that version of API responses)... I suppose only controller actions and their views would differ from version to version, and models are easy to handle with just extending the logic in them. Yes, this could be done with interface, but I see it unnatural for rails MVC architecture. --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---