比如说,我们正在使用React和ES6.我们将React和Component导入为
import React from 'react'
import { Component } from 'react'
Run Code Online (Sandbox Code Playgroud)
为什么语法不同?我们不能按照下面的规定使用吗?
import Component from 'react'
Run Code Online (Sandbox Code Playgroud) 我在我的rails 4.0.1项目中使用了fontawesome 3.2.1和bootstrap 3.0.0.我的所有资产都位于供应商/资产中.
问题是我的fontawesome正在开发模式,当我编译我的资产(生产环境)并在生产环境中运行服务器,它无法加载fontawesome.错误是
Started GET "/assets/fontawesome-webfont.svg" for 127.0.0.1 at 2014-01-08 11:48:55 +0530
ActionController::RoutingError (No route matches [GET] "/assets/fontawesome-webfont.svg"):
actionpack (4.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (4.0.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
Run Code Online (Sandbox Code Playgroud)
资产是
$ls vendor/assets/
=> fonts images javascripts stylesheets
$ls vendor/assets/*
=> vendor/assets/fonts:
FontAwesome.otf fontawesome-webfont.ttf glyphicons-halflings- regular.svg
fontawesome-webfont.eot fontawesome-webfont.woff glyphicons-halflings- regular.ttf
fontawesome-webfont.svg glyphicons-halflings-regular.eot glyphicons-halflings-regular.woff
vendor/assets/images:
bg_direction_nav.png bxslider search-icon.jpg
vendor/assets/javascripts:
bootstrap bxslider fancybox others revolution_slider
vendor/assets/stylesheets:
bootstrap bxslider fancybox font_awesome others revolution_slider
$ls vendor/assets/stylesheets/bootstrap/
=> bootstrap.min.css
$ls vendor/assets/stylesheets/font_awesome/
=> font-awesome.css
Run Code Online (Sandbox Code Playgroud)
我的application.css是
$cat app/assets/stylesheets/application.css
/* …Run Code Online (Sandbox Code Playgroud) 我正在学习弹性搜索.我在'mapping.json'中指定了映射.它的内容是
{
"book" : {
"_index" : {
"enabled" : true
},
"_id" : {
"index": "not_analyzed",
"store" : "yes"
},
"properties" : {
"author" : {
"type" : "string"
},
"characters" : {
"type" : "string"
},
"copies" : {
"type" : "long",
"ignore_malformed" : false
},
"otitle" : {
"type" : "string"
},
"tags" : {
"type" : "string"
},
"title" : {
"type" : "string"
},
"year" : {
"type" : "long",
"ignore_malformed" : false,
"index" : …Run Code Online (Sandbox Code Playgroud) 我试图理解Ruby对象模型.我知道实例方法保存在类中而不是类的对象中,因为它删除了冗余.我读到,每当创建一个类时,也会为新创建的类创建元类.元类存储类方法.即类的单例方法位于元类中.例如
class MyClass
def hi
'hi object'
end
def self.bye
'bye singleton method'
end
end
Run Code Online (Sandbox Code Playgroud)
对于上面的MyClass,也创建了一个元类(比如说#MyClass).现在方法'hi'是一个实例级方法,可以在MyClass的所有对象上调用.方法'bye'是MyClass的单例方法,它驻留在#MyClass中.原因(我认为是这样)为什么'hi'被保存在MyClass而不是MyClass的所有对象中是因为它避免了冗余.但我们不能有多个名为MyClass的类.那么为什么不在MyClass而不是#MyClass中存储'bye',因为我们不能拥有多个MyClass.我完全不知道为什么会这样,我只是想了解它背后的原因.
----- UPDATE ----
元类存储类信息,如单例方法和其他东西.但是由于一个类是一个单例对象(它是一个类的实例,并且只是它的类型),那么为什么不将所有信息保存在类本身而不是元类中.
我是AngularJS的新手.我正在使用rails应用程序以json格式公开数据.该数据将由角度应用程序使用.角度回购和铁路回购完全不同.不同存储库的原因是因为我希望我的rails repo只是使用我可以在角度应用程序中使用的API来公开数据.
我的rails控制器如下
class Api::V1::PhonesController < ApplicationController
def index
render json: Phone.all
end
def show
render json: Phone.find(params[:id])
end
...
end
Run Code Online (Sandbox Code Playgroud)
现在,当我访问'localhost:3000/api/v1/phones'时,它会返回所有手机的json数据.当我访问'localhost:3000/api/v1/phones/1'时,它返回id为1的手机的json数据.我使用http://jsonlint.com/验证了json数据格式.一切都很好,直到这里.
我的angularjs路由文件如下:
$routeProvider.
when('/phones', {
templateUrl: 'list.html',
controller: 'PhoneListController'
}).
when('/phones/:id', {
templateUrl: 'show.html',
controller: 'PhoneShowController'
}).
otherwise({
redirectTo: '/phones'
});
}]);
Run Code Online (Sandbox Code Playgroud)
我在angular repo中的index.html中嵌入了list.html模板.
<html ng-app='phoneCatApp'>
...
</html>
<script type="text/ng-template" id="list.html">
This is the list template.
</script>
Run Code Online (Sandbox Code Playgroud)
services.js的代码如下:
var appServices = angular.module('appServices', []);
phoneCatApp.factory('appServices', ['$http', '$q', function($http, $q){
var url = "http://localhost:3000/api/v1/";
//get all phones
this.getPhones = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用pdfkit将显示图像从facebook cdn转换为pdf的html页面.我使用rails 4.2,pdfkit 0.6.2和wkhtmltopdf-binary 0.9.9.3.
# Gemfile
gem 'pdfkit'
gem 'wkhtmltopdf-binary'
# controller
def generate_pdf
@booklet = Booklet.find params[:id]
@cover = Image.last
@images = @booklet.images.sort_by(&:uploaded_at)
respond_to do |format|
format.html
format.pdf do
html = render_to_string(layout: true , action: "generate_pdf.html.haml")
kit = PDFKit.new(html, page_size: 'A4', orientation: 'Landscape')
`sass vendor/assets/stylesheets/bootstrap.scss tmp/bootstrap.css`
`sass vendor/assets/stylesheets/custom.scss tmp/custom.css`
kit.stylesheets << "#{Rails.root}/tmp/bootstrap.css"
kit.stylesheets << "#{Rails.root}/tmp/custom.css"
pdf = kit.to_pdf
send_data pdf, filename: 'booklet.pdf', type: 'application/pdf'
end
end
end
# application.scss
@import 'bootstrap';
@import 'custom';
# config/application.rb
require 'pdfkit'
config.middleware.use …Run Code Online (Sandbox Code Playgroud) 我有一个使用Facebook登录功能的rails(4.2.0)应用程序.主要的宝石是设计(3.4.0)和omniauth-facebook(2.0.0).我已在Facebook上注册该应用程序,并一直在使用其测试应用程序进行开发.Facebook登录功能适用于开发环境.
当尝试在生产服务器上使用Facebook登录功能时,我收到错误"应用程序配置不允许给定URL:应用程序的设置不允许使用一个或多个给定的URL.它必须与网站URL或Canvas URL或域必须是App域之一的子域."
在dev env中使用的测试应用程序设置的详细信息如下 -
Settings:
Basic:
App Domains: 'localhost'
Website:
Site URL: 'http://localhost:3000'
Advanced:
OAuth Settings:
Embedded browser OAuth Login: Yes
Valid OAuth redirect URIs: "http://localhost:3000/users/auth/facebook/callback"
Run Code Online (Sandbox Code Playgroud)
生产环境中使用的注册应用程序设置的详细信息如下 -
Settings:
Basic:
App Domains: 'www.mysite.co'
Website:
Site URL: 'http://www.mysite.co'
Advanced:
OAuth Settings:
Embedded browser OAuth Login: Yes
Valid OAuth redirect URIs: "http://www.mysite.co/users/auth/facebook/callback"
Run Code Online (Sandbox Code Playgroud)
我在secretts.yml中指定了以下内容
development:
secret_key_base: some_secret_key
facebook:
app_id: test_app_id
app_secret: test_app_secret
production:
secret_key_base: some_secret_key
facebook:
app_id: registered_app_id
app_secret: registered_app_secret
Run Code Online (Sandbox Code Playgroud)
并且一直在设计初始化中使用来自secrets.yml的信用 …
这个问题更多的是理论而不是源代码。
我有一个 ES 2.x 节点,它有超过 1.2TB 的数据。我们有 40 多个索引,每个索引至少有 1 种类型。在这里,ES 2.x 被用作数据库而不是搜索引擎。用于将数据转储到 ES 2.x 的源丢失了。此外,数据未规范化,但单个 ES 文档具有多个嵌入文档。我们的目标是重新创建数据源,同时对其进行规范化。
我们正在计划的是:
我们使用的是 JRuby 9.1.15.0、Rails 5、Ruby 2.4 和 Sidekiq。
目前,我们正在从 ES 检索特定日期时间范围的数据。有时我们会收到 0 条记录,有时会收到 100000+ 条记录。问题是当我们收到大量记录时。
下面是一个示例脚本,当日期范围的数据很小时可以工作,但在数据很大时会失败。1.2TB/40 索引是平均索引大小。
class DataRetrieverWorker
include Sidekiq::Worker
include Sidekiq::Status::Worker
def perform(indx_name, interval = 24, start_time = nil, end_time = nil)
unless start_time || end_time
client = ElasticSearchClient.instance.client
last_retrieved_at = RetrievedIndex.where(name: indx_name).desc(:created_at).first
start_time, end_time = unless …Run Code Online (Sandbox Code Playgroud) 我正在部署使用mina部署的rails 4应用程序.我的部署脚本是
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rvm' # for rvm support. (http://rvm.io)
set :domain, 'someplace.com'
set :deploy_to, '/home/deploy/projects/website'
set :repository, 'git@github.com:someone/repo.git'
set :branch, 'master'
set :identity_file, "#{ENV['HOME']}/.ssh/id_rsa"
set :user, 'deploy' # Username in the server to SSH to.
set :shared_paths, ['config/database.yml', 'config/credentials.yml', 'log', 'tmp']
task :environment do
invoke :'rvm:use[ruby-2.1.0@default]'
end
task :setup => :environment do
queue! %[mkdir -p "#{deploy_to}/shared/log"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
queue! %[mkdir -p "#{deploy_to}/shared/config"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config"]
queue! %[touch "#{deploy_to}/shared/config/database.yml"]
queue %[echo "-----> …Run Code Online (Sandbox Code Playgroud) 我正在使用http://ivaynberg.github.io/select2/在rails-emberjs应用程序中提供自动完成功能.我有some_dynamic_id值.我的车把代码如下:
{{
view App.TokenAutoCompleteView
searchUrl="/users/" + some_dynamic_id + "/books/search"
optionValuePath="content.id"
optionLabelPath="content.name"
multiple="false"
}}
Run Code Online (Sandbox Code Playgroud)
我想为searchUrl属性分配一个动态创建的URL.我尝试在车把模板的href标签中使用来自Ember Interpolation的 bind-attr,但无法使其正常工作.
ruby ×2
angularjs ×1
curl ×1
deployment ×1
ecmascript-6 ×1
ember.js ×1
font-awesome ×1
http ×1
jsonp ×1
pdfkit ×1
reactjs ×1
sidekiq ×1