【发布时间】:2015-10-15 17:17:07
【问题描述】:
我正在尝试在我的 Ruby 应用程序中使用 Haml 文件,但出现以下错误:
NoMethodError at /issues
undefined method `map' for "localhost:27017":String
index.haml in block in singleton class
9. -@issues.each do |issue|
app.rb in block in <class:App>
14. haml :"issues/index"
这是我的 index.haml 文件:
%h1 All Issues
%table.table.table-hover
%thead
%tr
%th Title
%th Description
%th Created at
-@issues.each do |issue|
%tr
%td
%a(href="/issues/#{issue.id}/edit")=issue.name
%td=issue.description
%td=issue.id.generation_time.ago_in_words
-unless @issues.any?
%tfoot
%tr
%th
There are no issues.
%a.btn.btn-primary(href="/issues/new") Create one
这里是 app.rb 文件:
require_relative "models/issue"
class App < Sinatra::Base
enable :sessions
register Sinatra::Flash
get "/" do
"redirect/issues"
end
get "/issues" do
@issues = Issue.all
haml :"issues/index"
end
end
问题似乎出在我的 -@issues.each 上 |issue|循环,但我确定问题出在 Ruby 语法或 Haml 或其他问题上。我还在 /models 目录中创建了一个 issue.rb 文件,如下所示:
class Issue
include Mongoid::Document
include Mongoid::Timestamps::Updated
field :name, type: String
field :description, type: String
end
编辑:我认为我的问题是问题未初始化。我收到一条错误消息:
uninitialized constant Issue::Mongoid (NameError)
【问题讨论】: