小编Jas*_*ost的帖子

Rails生成器错误rspec [未找到]

我正在使用Rails 4.1.1

当我执行命令时 rails g generator my_generator

生成器运行但始终以 error rspec [not found]

我已将rspecrspec-rails宝石添加到我的Gemfile中。

我想走哪一步呢?

rspec generator rspec-rails ruby-on-rails-4

6
推荐指数
1
解决办法
1505
查看次数

ExpressJS 4在res.send()之后执行函数

我是 NodeJS 和异步编程的新手。我使用express作为我的应用程序的基础,实际上只有一个路由服务页面并接受从表单上传的内容。我想在文件上传后向外部服务发出 POST 请求。然而,尝试在 res.send(200) 之后执行任何代码会导致以下错误消息Error: Can't set headers after they are sent.

我正在使用请求包将帖子发送到外部服务。

var express = require('express');
var router = express.Router();
var util = require("util");
var request = require("request");

/* POST uploads. */
router.post('/', function(req, res, next) {
    console.log("LOG:" + util.inspect(req.files));
    res.send('respond with a resource');
    postFile(req.files.file.path);
});

var postFile = function(path) {
    var opts = {
        method: 'POST',
        uri: 'https://example.com/api/files.upload',
        formData: {
            token: "xxx",
            file: fs.createReadStream(req.files.file.path)
        }
    }

    // console.log("LOG:\n" + util.inspect(opts));

    request.post(opts, function(error, response, …
Run Code Online (Sandbox Code Playgroud)

node.js express express-4

5
推荐指数
1
解决办法
6451
查看次数

在 ruby​​ on rails 中存储类的位置

我需要为我的应用程序创建一个具有一些属性和方法的类,我应该在哪里将类文件存储在 ruby​​ on rails 应用程序中?

ruby-on-rails class

4
推荐指数
1
解决办法
1224
查看次数

理解before和after_filter

我的控制器类声明后,我有以下代码

  before_filter :load_form, :except => [:create, :update, :delete]
  after_filter :load_form, :only => [:create, :update, :delete]

  def load_form
    @severities = Severity.all
    @severity = Severity.new
  end
Run Code Online (Sandbox Code Playgroud)

当页面加载得很好时,我得到严重性列表,这意味着before_filter正在工作.但是在调用诸如创建严重性列表之类的方法后,总是会返回为零.我想我可能只是遗漏了一些关于过滤器的基本信息.任何人都可以帮助我理解为什么after_filter不起作用?

before-filter ruby-on-rails-3

4
推荐指数
1
解决办法
1万
查看次数

Ruby on Rails link_to路径路径,同时保留原始查询字符串参数

我有一个像http://example.com/?sort=pop这样的网址

在我看来,我正在使用 link_to category.name, categories_path(category)

如何保留请求URL上可能已存在的任何查询字符串参数?

因此,最终的链接网址为http://example.com/categories/1?sort=pop

html-helper ruby-on-rails

4
推荐指数
1
解决办法
4023
查看次数

RVM Ruby on Snow Leopard

我安装了RVM,然后安装了最新版本的Ruby.现在当我尝试生成一个新的rails应用程序时,我收到以下错误消息.

    NOTE: Gem::Specification#default_executable= is deprecated with no replacement. It will be removed on or after 2011-10-01.
    Gem::Specification#default_executable= called from /Users/local/.rvm/gems/ruby-1.9.2-p180@global/specifications/rake-0.8.7.gemspec:10.
    NOTE: Gem::Specification#default_executable= is deprecated with no replacement. It will be removed on or after 2011-10-01.
    Gem::Specification#default_executable= called from /Users/local/.rvm/gems/ruby-1.9.2-p180/specifications/rake-0.8.7.gemspec:10.
    NOTE: Gem::Specification#default_executable= is deprecated with no replacement. It will be removed on or after 2011-10-01.
    Gem::Specification#default_executable= called from /Users/local/.rvm/gems/ruby-1.9.2-p180/specifications/rubygems-update-1.8.1.gemspec:11.
    /Library/Ruby/Site/1.8/rubygems/dependency.rb:247:in `to_specs': Could not find rails (>= 0) amongst [rake-0.8.7, rake-0.8.7, rubygems-update-1.8.1] (Gem::LoadError)
        from /Library/Ruby/Site/1.8/rubygems/dependency.rb:256:in `to_spec'
        from /Library/Ruby/Site

/1.8/rubygems.rb:1182:in `gem'
    from /usr/bin/rails:18 …
Run Code Online (Sandbox Code Playgroud)

rvm ruby-on-rails-3

2
推荐指数
1
解决办法
3550
查看次数

PhantomJS传递参数进行评估

我有一个小的测试应用程序使用NightmareJS作为PhantomJS的包装我想测试元素是否存在类.我有这个代码:

new Nightmare()
  .goto(baseURL)
  .evaluate(function() {
    return document.querySelector('body');
  }, function(element) {
    element.className.should.equal(expected)
    callback();
  })
  .run();
Run Code Online (Sandbox Code Playgroud)

如何将参数传递给querySelector方法而不是对代码进行硬编码?

我试过了

var tag = body;
new Nightmare()
      .goto(baseURL)
      .evaluate(function() {
        return document.querySelector(tag);
      }, function(element) {
        element.className.should.equal(expected)
        callback();
      })
      .run();
Run Code Online (Sandbox Code Playgroud)

但是,PhantomJS始终返回一个无法找到变量的错误.

如何将变量参数传递给querySelector方法?

javascript node.js phantomjs nightmare

2
推荐指数
1
解决办法
1686
查看次数

Ruby on Rails条件样式表

我想知道Ruby on Rails是否有一种优雅的方式来显示条件样式表,还是我需要使用默认值

    <!--[if IE 7]>
<link rel="stylesheet" href="css/ie7.css" type="text/css" media="screen" />
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails stylesheet

1
推荐指数
1
解决办法
1774
查看次数