显然我对铁轨很新,所以坚持下去.
我在我的模型中添加了一个构造函数
class Movie < Media
attr_accessible :director, :studio
attr_accessor :director, :studio
validates_presence_of :director, :studio, :title
def initialize title, director, studio
@title = title
@director = director
@studio = studio
end
end
Run Code Online (Sandbox Code Playgroud)
那种搞砸了我的东西.因为我在我的控制器中有一个方法'new'就像这样
def new
@movies = Movie.new
end
Run Code Online (Sandbox Code Playgroud)
并且在初始化出现之前它工作得很好.它需要将参数传递给'new'方法,但这是在视图打开后从用户传递参数并保存它们时完成的.现在我无法打开该视图,因为我收到错误
wrong number of arguments (0 for 3)
Run Code Online (Sandbox Code Playgroud)
添加构造函数是因为我开始为我的应用程序编写测试,并且为构造函数设置默认值会使该测试无效.解决这个问题的建议?
编辑:我的测试看起来像这样:
require 'spec_helper'
describe Movie do
before :each do
@movie = Movie.new "Bullet", "John", "20th"
end
describe "#{new}" do
it "returns new object of Movie" do
@movie.should be_an_instance_of Movie
end
it "throws …Run Code Online (Sandbox Code Playgroud) 我一直试图为我的项目写一些种子,但我遇到了一些障碍.
我many-to-many与我users和roles桌子有关系.因此,当我播种数据库时,我需要将一个带有正确ID的记录添加到我的连接表中.为了做到这一点,我需要找到用户email和角色,name并得到ids这个问题.我在sequelize网站上找不到任何好的文档.我正在使用sequelize-cli进行播种和迁移.我得到一个参数a queryInterface,但我找不到任何例子或提到这件事实际上可以做什么.只是一些简单的例子让我通过迁移(某种方式)和我能够在谷歌上找到的东西.
我通过使用"肮脏的伎俩"解决了这个问题我会说......
// user_seeds.js
up: function (queryInterface, Sequelize) {
return queryInterface.bulkInsert(table, [{
id: 1,
name: 'John doe',
email: 'john@doe.com',
created_at,
updated_at
}], {});
// roles_seeds.js
up: function (queryInterface, Sequelize) {
return queryInterface.bulkInsert(table, [{
id: 1,
name: 'admin',
created_at,
updated_at
}, {
id: 2,
name: 'user',
created_at,
updated_at
}]);
//user_roles_seeds.js
up: function (queryInterface, Sequelize) {
return queryInterface.bulkInsert(table, [{
employee_id: 1,
role_id: 1 …Run Code Online (Sandbox Code Playgroud) 只是想不出来这个.我发现关于快递会议的一切都说得很有效,然而,对我来说并非如此.
我的整个应用配置
app.configure ->
app.set 'port', process.env.PORT || 3000
app.set 'views', path.join(__dirname, 'views')
app.set 'view engine', 'jade'
app.use express.favicon()
app.use express.logger('dev')
app.use express.json()
app.use express.urlencoded()
app.use express.methodOverride()
app.use app.router
app.use express.static(path.join(__dirname, 'public'))
app.use express.bodyParser()
app.use express.cookieParser()
sessionStore = new express.session.MemoryStore
app.use express.session secret: 'key', store: sessionStore
Run Code Online (Sandbox Code Playgroud)
但这req.session只是undefined.我想用它来进行用户身份验证 - 非常基本.出于某种原因,事实证明对我来说非常艰难.
我在用express 3.5.0.
我的控制器atm看起来像这样:
class AuthenticationController
signUp: (req, res) ->
console.log req.body._id
console.log req.session
res.status(200).send req.body
module.exports = AuthenticationController
Run Code Online (Sandbox Code Playgroud)
和路线:
format = require './middlewares/format'
AuthenticationController = …Run Code Online (Sandbox Code Playgroud) 我遇到了一些麻烦rabl.这段代码
collection favourite_groups, root: :groups
extends 'favourites/base'
Run Code Online (Sandbox Code Playgroud)
给了我以下json结构:{ groups: [ {..}, {..} ] }.我需要的是附加另一个包含数组的节点 - { groups: [ {..}, {..} ], users: [ {..}, {..} ] }数据在单独的变量中,但它可以在一个中,这使得它可以工作.
想法?
node.js ×2
collections ×1
express ×1
json ×1
parameters ×1
rabl ×1
sequelize.js ×1
session ×1
undefined ×1