create custom html helpers in ruby on rails

前端 未结 1 536
终归单人心
终归单人心 2020-12-08 13:50

I\'ve starting programming on ASP.NET MVC Framework a year ago. Recently. I\'ve learning Ruby On Rails Framework There is \"custom html helper\" feature in ASP.NET MVC So I

相关标签:
1条回答
  • 2020-12-08 14:03

    To create a new helper:

    1. choose a name for the helper file, for instance tags_helper.rb
    2. create the file in the /app/helpers directory
    3. create a module according to the file name. In this case

      module TagsHelper
      end
      
    4. define your helper as method

      module TagsHelper
        def hello_world(name)
          "hello #{name}"
        end
      end
      

    Now you can use the hello_world helper method in your view.

    0 讨论(0)
提交回复
热议问题