Use of Helpers

135 views
Skip to first unread message

Andrew Burleson

unread,
May 5, 2016, 2:41:12 PM5/5/16
to Roda
I assume that if we have a basic app:

class MyApp < Roda

end

and some helper module like:

module UserHelpers
  def current_user
    @user ||= User[ session[:user_id] ]
  end
end

That the expected use of helpers is just:

include UserHelpers


This seems to work fine. Is there any other recommended practice for creating your own helper modules / methods so that they place nice with Roda?

I found a reference to "larger applications using helpers" in the Conventions section of the Roda guide, but no other mention.


Thanks!

Andrew

Jeremy Evans

unread,
May 5, 2016, 3:13:26 PM5/5/16
to Roda
That's the correct way to do it.  Helper methods are just instance methods in the Roda subclass, so including a module is fine, as is defining instance methods directly in the class.   I guess this isn't mentioned in the README.  If you think it should be added, please send in a pull request.

Thanks,
Jeremy

Andrew Burleson

unread,
May 5, 2016, 4:20:30 PM5/5/16
to Roda
Thanks Jeremy!
Reply all
Reply to author
Forward
0 new messages