Newbie stuff: Adding a New Library Class


I have been successful in playing around with model, views and
controllers in Rails. Along the way, I learnt that some of the reusable
stuff could be made library classes. I want to create a lib which will
render a form and form elements.

I created a class Mylib.rb in /lib folder.
The class tructure looks like this

class Mylib
helper FormTagHelper

attr_accessor :name, :range, :name, :category, :sort, :page, 

:height, :width …

def initialize(name, options = {})
    @name = name
    @range = options[:range]
    @category = options[:category]

When I run this code, I get two errors:

  1. Symbol as array index
    This is on the line @range = options[:range]

  2. And further, I want to use form tag helpers in my class. I need to
    use select_tag, options_for_select in the lib. I am not sure how to do
    this. Please, please someone help me in the right direction.



This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs