Forum: Ruby on Rails weakness of helper?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F78258e63d2879413ebf4558d74c1a9e?d=identicon&s=25 Kevin Yang (Guest)
on 2007-06-18 06:38
(Received via mailing list)
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
58c6efb8466b9f85155fe6aa9fc37fce?d=identicon&s=25 Chris Taggart (christ)
on 2007-06-26 12:06
(Received via mailing list)
Kevin Yang wrote:
> in helper .
>
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
58c6efb8466b9f85155fe6aa9fc37fce?d=identicon&s=25 Chris Taggart (christ)
on 2007-06-26 12:10
(Received via mailing list)
Chris T wrote:
>>       However i agree that some html intensive code still sites best
>>
>
> 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
This topic is locked and can not be replied to.