Mubashar Abbas
Mubashar Abbas

Reputation: 5673

Rails helper method error content_tag

I am ruby beginner, I am following a rails course, and this method works for the instructor but not for me, I get a syntax error.

module SubjectsHelper
    def status_tag (boolean, options={})
        options[:true_text] ||= ''
        options[:false_text] ||= ''

        if boolean
            content_tag (:span, options[:true_text], :class => "status true")
        else
            content_tag (:span, options[:false_text], :class => "status false")
        end

    end
end

The error I get is:

syntax error, unexpected ',', expecting ')' content_tag (:span, options[:true_text], :class => "status true") ^

The line number in error message points to the first call to content_tag. I have double checked with the video, and I don't know what is wrong,

I event tried wrapping :class => "status true" in {} and I got the same error.

Upvotes: 0

Views: 152

Answers (1)

Narasimha Reddy - Geeker
Narasimha Reddy - Geeker

Reputation: 3890

Please change this to

content_tag(:span, options[:true_text], class: "status true")

please read the docs before using a method. Here is docs for content_tag

Upvotes: 1

Related Questions