【问题标题】:Rails helper method error content_tagRails 辅助方法错误 content_tag
【发布时间】:2017-06-20 06:24:26
【问题描述】:

我是 ruby​​ 初学者,我正在学习 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

我得到的错误是:

语法错误,意外 ',',期待 ')' content_tag (:span, options[:true_text], :class=> "status true") ^

错误消息中的行号指向第一次调用content_tag。我仔细检查了视频,我不知道出了什么问题,

我尝试将:class => "status true" 包装在{} 中,但我得到了同样的错误。

【问题讨论】:

标签: ruby-on-rails ruby


【解决方案1】:

请改成

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

请在使用方法之前阅读文档。这是content_tag的文档

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-30
    • 2016-07-22
    • 1970-01-01
    • 2012-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多