简体   繁体   English

Rails助手方法错误content_tag

[英]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. 我是红宝石初学者,我正在学习Rails课程,并且此方法适用于教师,但不适用于我,我遇到语法错误。

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") ^ 语法错误,意外的',',期望为')'content_tag(:span,options [:true_text],:class =>“ status true”)^

The line number in error message points to the first call to content_tag . 错误消息中的行号指向对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. 我尝试在{}包装:class => "status true" ,但我遇到了同样的错误。

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 这是content_tag的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM