.erb,.rhtml和.html.erb有什么区别?
我想编写一个shell脚本(.sh文件)来获取给定的进程ID.我在这里尝试的是,一旦我获得进程ID,我想杀死该进程.我在Ubuntu(Linux)上运行.
我能用命令这样做
ps -aux|grep ruby
kill -9 <pid>
Run Code Online (Sandbox Code Playgroud)
但我不知道如何通过shell脚本来做到这一点.
我正在尝试为我的Angular控制器编写一个测试,我正在使用jasmine karma它angular-mocks,但一直在收到错误ReferenceError: Can't find variable: module.
我有一点搜索,但我已经有了angular-mocks我的凉亭.
我在这里可以缺少什么?
以下是我的代码:
#controller
angular.module('cook_book_ctrl', [])
.controller('cookBookCtrl', function($scope, CookBook, CookBookRecipesService){
$scope.cookbookoptions = true;
CookBook.list()
.success(function(data){
$scope.recipeList = data;
CookBookRecipesService.loadCookBookRecipes($scope.recipeList);
})
.error(function(error){
})
});
#controller test
describe('CookBook controller spec', function(){
var $httpBackend, $rootScope, createController, authRequestHandler
beforeEach(module('cook_book_ctrl'));
})
#bower.json
{
"name": "HelloIonic",
"private": "true",
"devDependencies": {
"ionic": "driftyco/ionic-bower#1.0.0",
"ionic-service-analytics": "master",
"ionic-service-core": "~0.1.4",
"angular-mocks": "1.3.13"
},
"dependencies": {
"ng-cordova-oauth": "~0.1.2",
"ng-tags-input": "~2.3.0",
"angular": "~1.4.0",
"underscore": "~1.8.3",
"materialize": …Run Code Online (Sandbox Code Playgroud) 我有一个现有的rails应用程序我在ruby 1.9.2和linux上运行它的rails版本
rails 2.3.8
Run Code Online (Sandbox Code Playgroud)
它还有一个GEMFILE,在它的vendor/gems目录中它有'fastercsv-1.5.4'gem
并且在它的迁移中(在两次迁移中)它需要gem'quickedcsv'
require 'fastercsv'
Run Code Online (Sandbox Code Playgroud)
但是,当我这样做
rake db:migrate
Run Code Online (Sandbox Code Playgroud)
它没有通过迁移声明
"请切换到Ruby 1.9的标准CSV库.它是FasterCSV加上对Ruby 1.9的m17n编码引擎的支持."
我发现消息来自gems'fast_csv.rb'文件.因为它有条件检查ruby版本
if RUBY_VERSION >= "1.9"
class FasterCSV
def self.const_missing(*_)
raise NotImplementedError, "Please switch to Ruby 1.9's standard CSV " +
"library. It's FasterCSV plus support for " +
"Ruby 1.9's m17n encoding engine."
end
def self.method_missing(*_)
const_missing
end
def method_missing(*_)
self.class.const_missing
end
end
-- and more code
Run Code Online (Sandbox Code Playgroud)
有人能告诉我如何解决这个问题.请注意,'fastercsv'尚未添加到GEMFILE中.
我有一个名为user的ActiveRecord模型(我在rails 2.3.8上),我将其保存为
user = User.new
user.name = "user name"
user.save!
Run Code Online (Sandbox Code Playgroud)
我想要做的是在创建用户后获取生成的用户ID.但目前它在保存时返回true/false值
如何获取已保存的用户ID?
我正试图找出一种方法来保持我的angular变量与页面刷新/跨控制器.我的工作流程是,
我尝试了两种方法,
1 - 将令牌分配给rootScope
不工作
2 - 使用a factory
#app.js
'use strict';
angular.module('recipeapp', [])
.run(['$rootScope', '$injector', 'Authenticate', function($rootScope,$injector, Authenticate){
$injector.get("$http").defaults.transformRequest = function(data, headersGetter) {
$injector.get('$http').defaults.headers.common['auth-token'] = Authenticate.getToken();
}
}]);
#factory
'use strict';
angular.module('recipeapp')
.factory('Authenticate', function(){
var factory = {};
var accessToken = "";
factory.setToken = function(token) {
accessToken = token;
}
factory.getToken = function() {
return accessToken;
}
return factory;
})
#facebook controller
I set the the token with every successful login
Authenticate.setToken(data.app_token);
Run Code Online (Sandbox Code Playgroud)
但问题是,如果我刷新页面,则 …
我想编写一个命名范围来从其id获取记录.
例如,我有一个名为的模型Event,我想模拟Event.find(id)使用以named_scope获得未来的灵活性.
我在我的模型中使用了这段代码:
named_scope :from_id, lambda { |id| {:conditions => ['id= ?', id] } }
Run Code Online (Sandbox Code Playgroud)
我从我的控制器那里叫它Event.from_id(id).但我的问题是它返回一个Event对象数组而不是一个对象.
因此,如果我想得到事件名称,我必须写
event = Event.from_id(id)
event[0].name
Run Code Online (Sandbox Code Playgroud)
而我想要的是
event = Event.from_id(id)
event.name
Run Code Online (Sandbox Code Playgroud)
我在这里做错了吗?
我正在尝试使用Angular构建一个静态站点.我想要的是将一些全局的css/js /图像文件添加到index.html
这是我的代码 index.html
<link rel="stylesheet" type="text/css" href="css/layers.css">
Run Code Online (Sandbox Code Playgroud)
我css在同一级别的文件夹index.html文件
我为我添加的每个样式表收到此错误(来自ng服务与chrome)
拒绝从' http:// localhost:4200/css/layers.css ' 应用样式,因为其MIME类型('text/html')不是受支持的样式表MIME类型,并且启用了严格的MIME检查.
我也试过添加它
#.angular-cli.json
"styles": [
"styles.css",
"css/layers.css"
],
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
我的角度设置是
Angular CLI: 1.6.5
Node: 8.1.4
OS: darwin x64
Angular: 5.2.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.6.5
@angular-devkit/build-optimizer: 0.0.42
@angular-devkit/core: 0.0.29
@angular-devkit/schematics: 0.0.52
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.5
@schematics/angular: 0.1.17
typescript: 2.5.3
webpack: 3.10.0
Run Code Online (Sandbox Code Playgroud) 有人能告诉我有没有办法将异常处理作为常用方法并在方法中使用?让我进一步解释一下.
例如,我有以下方法
def add(num1, num2)
begin
num1 + num2
rescue Exception => e
raise e
end
end
def divide(num1, num2)
begin
num1 / num2
rescue Exception => e
raise e
end
end
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,即使我的方法只需要一行,由于异常处理代码,该方法变得更大.
我正在寻找的是更轻薄的解决方案(只是一个想法)
def add(num1, num2)
num1 + num2 unless raise_exception
end
def divide(num1, num2)
num1 / num2 unless raise_exception
end
def raise_exception
raise self.Exception
end
Run Code Online (Sandbox Code Playgroud)
请注意上面的代码不起作用,只是我的想法.这可能还是有其他好方法吗?
ruby ×3
activerecord ×2
angularjs ×2
angular ×1
bash ×1
cdn ×1
css ×1
erb ×1
fastercsv ×1
find ×1
gem ×1
javascript ×1
linux ×1
mime-types ×1
page-refresh ×1
rhtml ×1
scripting ×1
shell ×1
testing ×1