有点混淆为什么这不起作用.我在Windows 7上使用Ruby 1.9.2和Rails 3.0.3.
尝试使用formtastic为post模型创建一个表单,然而,当我尝试渲染视图时,我继续为NilClass:Class获取未定义的方法`model_name'.
相关代码:
Demonly_controller.rb
class DemonlyController < ApplicationController
def index
@post = Post.all
end
end
Run Code Online (Sandbox Code Playgroud)
Posts_controller.rb
class PostsController < ApplicationController
end
Run Code Online (Sandbox Code Playgroud)
Post.rb
class Post < ActiveRecord::Base
attr_accessible :title, :post, :date, :time, :user, :visible, :comments
end
Run Code Online (Sandbox Code Playgroud)
Index.html.erb
<h1>Demonly</h1>
<% semantic_form_for @post do |f|%>
<%= f.errors %>
<%= f.inputs do %>
<%= f.input :title %>
<%= f.input :post %>
<%= f.input :date %>
<%= f.input :time %>
<%= f.input :user %>
<%= f.input :visible %> …Run Code Online (Sandbox Code Playgroud) 这是相关的代码:
app.get('/all', function(req,res) {
Party.find({},[],function(p) {
console.log(p);
});
res.redirect('/');
});
Run Code Online (Sandbox Code Playgroud)
应该返回数据库中的所有集合 - 在控制台中返回null.
var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost/impromptu');
var Schema = mongoose.Schema, ObjectId = Schema.ObjectId;
Run Code Online (Sandbox Code Playgroud)
初始化的一般事项
var PartySchema = new Schema({
what : String,
when : String,
where : String
});
mongoose.model('Party',PartySchema);
// Models
var Party = db.model('Party');
Run Code Online (Sandbox Code Playgroud)
模式
我有其他一切正确设置,我可以保存集合很好,由于某种原因无法检索所有...
检查了/var/log/mongodb.log,它确实是连接的.
有任何想法吗?