How to create and use a module?

Discussion in 'Ruby' started by Paweł Stawicki, Aug 7, 2007.

  1. Hi,

    I am quite new to ruby and ruby on rails. I am trying to user helper
    module in my controller but fail :( I added languages_helper.rb file to
    helpers directory in my RoR app. The file looks like this:

    module LanguagesHelper

    def LanguagesHelper.sort_to_first(langs, lang)
    ...my secret method here...
    end

    end

    Then I want to use it in LanguagesController. I put

    require "languages_helper"

    right in the beginning of the class body, and then in one of
    controller's methods I try to do

    ordered_langs = LanguagesHelper.sort_to_first(all_langs, lang)

    When while browsing I come to this place in my browser, there is a message:

    undefined method `sort_to_first' for LanguagesHelper:Module

    What is wrong?

    Best regards
    Pawel Stawicki
    Paweł Stawicki, Aug 7, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maric Michaud
    Replies:
    0
    Views:
    7,181
    Maric Michaud
    Jun 24, 2006
  2. -ecosys.com
    Replies:
    4
    Views:
    293
    Calvin Spealman
    Sep 28, 2007
  3. Krithika San
    Replies:
    3
    Views:
    326
    Marnen Laibow-Koser
    Nov 14, 2009
  4. Replies:
    4
    Views:
    197
    Uri Guttman
    Jan 31, 2006
  5. Sam
    Replies:
    7
    Views:
    65
    Marcel Rodrigues
    Feb 9, 2014
Loading...

Share This Page