Hi , It comes to me that helper has some weaknesses: 1) It is hard to test . No easy way to write test code for it. (or Just i didn''t know?) 2) Not easy to reuse it on other controller/view/model. it looks like to that putting the helper code into a model (a fully helper model , or a mixed model) is good practice. However i agree that some html intensive code still sites best in helper . Any idea? thanks Kevin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Kevin Yang wrote:> Hi , > It comes to me that helper has some weaknesses: > 1) It is hard to test . No easy way to write test code for it. > (or Just i didn''t know?) > 2) Not easy to reuse it on other controller/view/model. > > it looks like to that putting the helper code into a model (a > fully helper model , or a mixed model) is good practice. > > However i agree that some html intensive code still sites best > in helper . > > Any idea? > > > thanks > Kevin > > > > > >1) You can test helpers, using TopFunky''s plugin (see http://nubyonrails.com/articles/test-your-helpers). 2) Well, you don''t generally want to reuse them in models - they are View helpers, after all. There''s been some discussion about presenter patterns in models, but I don''t see a consensus appearing yet (and there''s way too much fu in those discussions for a relative amateur like me to have a view). However, if you have a pattern which you genuinely need to have in both the controller and the helper (the current_user is a classic example), you can define as a provate method in the controler and then make available to the view by calling helper :some_method in the relevant controller Cheers Chris -- ---------------------------- http://autopendium.com Stuff about old cars --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Chris T wrote:> Kevin Yang wrote: >> Hi , >> It comes to me that helper has some weaknesses: >> 1) It is hard to test . No easy way to write test code for it. >> (or Just i didn''t know?) >> 2) Not easy to reuse it on other controller/view/model. >> >> it looks like to that putting the helper code into a model (a >> fully helper model , or a mixed model) is good practice. >> >> However i agree that some html intensive code still sites best >> in helper . >> >> Any idea? >> >> >> thanks >> Kevin >> >> >> >> >> >> > 1) You can test helpers, using TopFunky''s plugin (see > http://nubyonrails.com/articles/test-your-helpers). > > 2) Well, you don''t generally want to reuse them in models - they are > View helpers, after all. > > There''s been some discussion about presenter patterns in models, but I > don''t see a consensus appearing yet (and there''s way too much fu in > those discussions for a relative amateur like me to have a view). > > However, if you have a pattern which you genuinely need to have in > both the controller and the helper (the current_user is a classic > example), you can define as a provate method in the controler and then > make available to the view by calling helper :some_method in the > relevant controller > > Cheers > Chris >Sorry that should be helper_method :some_method Doh! -- ---------------------------- http://autopendium.com Stuff about old cars --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---