小编Jea*_*ean的帖子

安装libv8(3.11.8.13)时发生错误,Bundler无法继续

运行捆绑安装后,我收到此错误:

Gem::Package::FormatError: no metadata found in /Users/jeanosorio/.rvm/gems/ruby-1.9.3-p286/cache/libv8-3.11.8.13-x86_64-darwin-12.gem
An error occurred while installing libv8 (3.11.8.13), and Bundler cannot continue.
Make sure that `gem install libv8 -v '3.11.8.13'` succeeds before bundling.
Run Code Online (Sandbox Code Playgroud)

我试着用

gem install libv8 -v '3.11.8.13'
Run Code Online (Sandbox Code Playgroud)

但我明白了

ERROR:  Error installing libv8:
    invalid gem format for /Users/jeanosorio/.rvm/gems/ruby-1.9.3-p286/cache/libv8-3.11.8.13-x86_64-darwin-12.gem
Run Code Online (Sandbox Code Playgroud)

这里有什么问题.请帮忙.

ruby rubygems ruby-on-rails-3.2

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

Rails和Redis

使用以下命令在我的控制台上启动redis服务器后:

redis-server
Run Code Online (Sandbox Code Playgroud)

我像这样执行以下ruby脚本:

script/user/generate_roster_kids.rb start
Run Code Online (Sandbox Code Playgroud)

但它不起作用,我得到:

generate_roster_kids] Pid not found, process seems doesn't exist!
[generate_roster_kids] Process daemonized with pid 1110 with thread and Forever v.0.3.2
Run Code Online (Sandbox Code Playgroud)

如果我再次执行相同的命令,我得到以下内容:

generate_roster_kids] Found pid 1110...
[generate_roster_kids] Waiting the daemon's death . DONE
[generate_roster_kids] Process daemonized with pid 1385 with thread and Forever v.0.3.2
Run Code Online (Sandbox Code Playgroud)

但它不起作用,我做错了什么.

这是generate_roster_kids.rb文件的内容:

#!/usr/bin/ruby
require 'rubygems' unless defined?(Gem)
require 'forever'
require 'redis'

Forever.run do
  REDIS = Redis.new()
  #
  # dir  "foo"     # Default: File.expand_path('../../', __FILE__)
  # file "bar"     # Default: __FILE__
  log  "bar.log" …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails redis

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

使用 mocha 和 chai 测试 fetch

我有以下示例测试:

import { assert } from 'chai'

function starWarsMovies () {
  fetch('http://swapi.co/api/films/')
    .then((res) => {
         return res.json()
     })
     .then((res) => res.count)
}

describe('Get star war movies', () => {
  it('should get 7', () =>{
    assert.equal(starWarsMovies(), 7)
  })
})
Run Code Online (Sandbox Code Playgroud)

但我得到

ReferenceError: fetch is not defined
Run Code Online (Sandbox Code Playgroud)

我必须使用什么才能测试提取请求。

更新


我也尝试过:

import { polyfill } from 'es6-promise'
import fetch from 'isomorphic-fetch'
Run Code Online (Sandbox Code Playgroud)

但后来我得到:

AssertionError: expected undefined to equal 7
Run Code Online (Sandbox Code Playgroud)

我不明白为什么。

javascript testing mocha.js chai fetch-api

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

Jest TypeError:fetch 不是函数

我有以下 Jest 测试代码来测试对端点提取

import MovieApiService from 'services/MovieApiService';
import movies from '../constants/movies';

describe('MovieApiService', () => {

  test('if jest work correctly', () => {
    expect(true).toBe(true);
  });

  test('get an array of popular movies', () => {
    global.fetch = jest.mock('../mocks/movies');
    const movieApiService = new MovieApiService();
    return movieApiService.getPopularMovies()
      .then(data => expect(data).toBe(movies));
  });
});
Run Code Online (Sandbox Code Playgroud)

但我得到:

在此处输入图片说明

我知道这movieApiService.getPopularMovies()是一个JavaScript fetch request,但是Node.js没有 fetch API,所以我如何才能使用 Jest 使这个测试工作?

javascript testing jestjs

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

填写输入文字

如何用值填充文本输入?我在尝试这个:

<input id="curso" maxlength="150" name="curso" size="40" type="text" 
    value="window.location.href.substring(91))" />
Run Code Online (Sandbox Code Playgroud)

但这不起作用.

javascript

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

JWT 在 ruby​​ on rails 上过期令牌

我正在尝试将过期时间设置为这样的 jwt 令牌:

class JsonWebToken
  def self.encode(payload)
    payload[:exp] = (2).minutes.from_now.to_i #expire in 2 minutes
    JWT.encode(payload, Rails.application.secrets.secret_key_base)
  end

  def self.decode(token)
    return HashWithIndifferentAccess.new(JWT.decode(token, Rails.application.secrets.secret_key_base)[0])
  rescue
    nil
  end
end
Run Code Online (Sandbox Code Playgroud)

但是当我尝试访问 url 时,令牌始终有效。此外,如果我解码令牌,我永远不会在哈希上获得 exp key:value。

任何建议

更新

我正在使用jwt gem

这就是我对用户进行身份验证的方式。

def authenticate_user
    user = User.find_for_database_authentication(email: params[:email])
    if user.valid_password?(params[:password])
      render json: payload(user)
    else
      render json: {errors: ['Invalid Username/Password']}, status: :unauthorized
    end
  end

  private

  def payload(user)
    return nil unless user and user.id
    {
      auth_token: JsonWebToken.encode({user_id: user.id}),
      user: {id: user.id, email: user.email}
    }
  end
Run Code Online (Sandbox Code Playgroud)

使用 curl …

ruby ruby-on-rails token jwt

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

在 nginx 服务器上反应路由器应用程序

我有一个应用程序,有两个路由器主页和结果。在主页中,我必须转到我们的授权微服务并返回到我的反应应用程序,返回结果页面,但是 result.html 文件不存在,因为是反应应用程序,所以我收到 404 错误。

我正在我的 nginx 上尝试以下配置:

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to …
Run Code Online (Sandbox Code Playgroud)

nginx reactjs react-router

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

生成重置密码令牌不保存在模型上

您好我尝试为我的rails应用创建重置密码; 但是当我尝试保存时,我收到以下错误:

验证失败:密码不能为空,密码太短(最少6个字符),密码确认不能为空

这是我的用户模型.

class User < ActiveRecord::Base
  attr_accessible :email, :password, :password_confirmation
  has_secure_password

  before_save { |user| user.email = email.downcase }
  before_save :create_remember_token

  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false }
  validates :password, presence: true, length: { minimum: 6 }
  validates :password_confirmation, presence: true

    def send_password_reset
        self.password_reset_token = SecureRandom.urlsafe_base64
        self.password_reset_at = Time.zone.now
        self.password = self.password
        self.password_confirmation = self.password
        save!
    end

  private

    def create_remember_token
        self.remember_token = SecureRandom.urlsafe_base64
    end

end
Run Code Online (Sandbox Code Playgroud)

方法"send_password_reset"不会更新用户,我不明白为什么尝试保存用户而不是只更新password_reset_token和password_reset_at.

请问有人可以帮助我吗?

ruby ruby-on-rails railscasts ruby-on-rails-3.2

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

Akka http丢失发件人参考

收到一个Future[httpResponse]我试图发送消息后,sender但我失去了参考sender.

这是我的接收方法的代码:

    def receive = {
        case Seq(method: HttpMethod, endpoint: String, payload: String) ? {
          // I have the correct sender reference
          implicit val materializer: ActorMaterializer = ActorMaterializer(ActorMaterializerSettings(context.system)) // needed by singleRequest method below
          // I have the correct sender reference

          val response: Future[HttpResponse] = Http(context.system).singleRequest(HttpRequest(method = method, uri = endpoint, entity = payload))
          println("http request sent")
          // I have the correct sender reference
          response onSuccess {
            case HttpResponse(statusCode, _, entity, _) ? { …
Run Code Online (Sandbox Code Playgroud)

scala akka akka-http

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

除非为nil,否则不要在数组上插入

我正在尝试查找和记录,记录是否为零,我不希望它在我的阵列上像这样:

@kid <<  Kid.find_only_kid(k) unless nil
Run Code Online (Sandbox Code Playgroud)

但是当我得到一个nil时,记录会插入到数组中.

这是我的模型上的find_only_kid方法的代码:

  def self.find_only_kid(kid)
    Kid.where(_id: kid.to_s, parent: false, teacher: false).first rescue nil
  end
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails mongoid

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