Rick Walsh
2007-Sep-01 21:18 UTC
Code reuse with rails (ex ASP.NET developer having trouble)
Hi, I''m converting a few of my existing websites from ASP.NET to Ruby on Rails, but I''m having a problem getting my head a round code re-use in ROR. For example, the site I am currently attempting to convert has different pages, whih each contain a comment block. A comment block includes a table of comments and a form to add another comment. So, I have a UsersController which handles all the pages related to a user i.e. the users homepage, there guestbook page etc I also have an ArtistsController which handles all the pages related to an artist i.e. a details page, the artists "art page listings", their shows etc etc I want to use the comments block (which includes the table and form) on pages which could be handled by either controller. I understand that I can split the comments view into a seperate partial view, and so the view can be re-used. BUT I dont want to have to put the code that handles interpreting the comments (which the user has typed into the comments form) in to both controllers!!! How can avoid this, I think I''m missing something!! Any help would be appreciated! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Wahid Lahlou
2007-Sep-01 22:49 UTC
Re: Code reuse with rails (ex ASP.NET developer having troub
I presume you have a comments controller. In this controller, you can either use a helper module (module CommentsHelper in /helpers/comments_helper), or a static method: def self.comments_handler #your code... end Hope this helps... -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Jeff
2007-Sep-02 00:08 UTC
Re: Code reuse with rails (ex ASP.NET developer having trouble)
On Sep 1, 4:18 pm, Rick Walsh <rick.wa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I''m converting a few of my existing websites from ASP.NET to Ruby on > Rails, but I''m having a problem getting my head a round code re-use in > ROR.If my suggestion below doesn''t help, try forum.softiesonrails.com, there tend to be a bunch of ex-.NET devs there willing to help.> BUT I dont want to have to put the code that handles interpreting the > comments (which the user has typed into the comments form) in to both > controllers!!! > > How can avoid this, I think I''m missing something!!Your partial helps with rendering the form from different controllers, but I''d suggest you still post your form data to the CommentsController''s create action. Then, you can redirect from there to wherever you want. This helps centralize where new comments are created - in the CommentsController - but you can still *render* comments from any controller''s view by sharing the partial around.> Any help would be appreciated!Does this help? Jeff softiesonrails.com essentialrails.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-/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 -~----------~----~----~----~------~----~------~--~---
Jack Zhan
2007-Sep-02 21:06 UTC
Re: Code reuse with rails (ex ASP.NET developer having trouble)
I suggest to define a method in your ApplicationController to process your comment, and the define before_filter in both of your UserController and ArtistController. On Sep 1, 8:08 pm, Jeff <cohen.j...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sep 1, 4:18 pm, Rick Walsh <rick.wa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > > I''m converting a few of my existing websites from ASP.NET to Ruby on > > Rails, but I''m having a problem getting my head a round code re-use in > > ROR. > > If my suggestion below doesn''t help, try forum.softiesonrails.com, > there tend to be a bunch of ex-.NET devs there willing to help. > > > BUT I dont want to have to put the code that handles interpreting the > > comments (which the user has typed into the comments form) in to both > > controllers!!! > > > How can avoid this, I think I''m missing something!! > > Your partial helps with rendering the form from different controllers, > but I''d suggest you still post your form data to the > CommentsController''s create action. Then, you can redirect from there > to wherever you want. > > This helps centralize where new comments are created - in the > CommentsController - but you can still *render* comments from any > controller''s view by sharing the partial around. > > > Any help would be appreciated! > > Does this help? > > Jeff > softiesonrails.com > essentialrails.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-/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 -~----------~----~----~----~------~----~------~--~---