SyntaxError: C:/Users/NEBELYN/Desktop/cms/simple_cms/app/models/subject.r
b:3: syntax error, unexpected =>, expecting ')'
scope :visible, lambda { where (:visible => true) }
^
C:/Users/NEBELYN/Desktop/cms/simple_cms/app/models/subject.rb:4: syntax e
rror, unexpected =>, expecting ')'
scope :invisible, lambda { where (:visible => false) }
^
C:/Users/NEBELYN/Desktop/cms/simple_cms/app/models/subject.rb:10: syntax
error, unexpected keyword_end, expecting '}'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/
active_support/dependencies.rb:424:in `load'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/
active_support/dependencies.rb:424:in `block in load_file'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/
active_support/dependencies.rb:616:in `new_constants_in'
当我的subject.rb文件看起来像这样
class Subject < ActiveRecord::Base
scope :visible, lambda { where (:visible => true) }
scope :invisible, lambda { where (:visible => false) }
scope :sorted, lambda {order("subjects.position ASC")}
scope :newest_first, lambda{ order("subjects.created_at DESC")}
scope :search. lambda { |query|
where (["name like ?", "%#{query}%"])
}
端 当我在rails控制台上运行此命令时“Subject.visible”请帮助
答案 0 :(得分:1)
您不能在where
和(
之间添加空格。
scope :visible, lambda { where (:visible => true) } # bad
scope :visible, lambda { where(:visible => true) } # good
答案 1 :(得分:0)
删除where
和open paranthesis
class Subject < ActiveRecord::Base
scope :visible, lambda { where(:visible => true) }
scope :invisible, lambda { where(:visible => false) }
scope :sorted, lambda {order("subjects.position ASC")}
scope :newest_first, lambda{ order("subjects.created_at DESC")}
scope :search. lambda { |query|
where(["name like ?", "%#{query}%"])
}