我正在将Rails 3.1.3用于具有Inherited Resources 1.3.0的项目.
当我有这样的控制器时:
class PostsController < InheritedResources::Base
end
Run Code Online (Sandbox Code Playgroud)
我用rspec测试以下内容
describe "PUT update" do
describe "with invalid params" do
it "re-renders the 'edit' template" do
post = Post.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Post.any_instance.stub(:save).and_return(false)
put :update, {:id => post.to_param, :post => {}}, valid_session
response.should render_template("edit")
end
end
end
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
3) PostsController PUT update with invalid params re-renders the 'edit' template
Failure/Error: response.should render_template("edit")
expecting <"edit"> but rendering with <"">
# ./spec/controllers/posts_controller_spec.rb:115:in `block …Run Code Online (Sandbox Code Playgroud) 我开始使用angular-ui按键模块,并想知道是否有办法使全局快捷键无论我放在体内的哪个位置都能正常工作.
我已经尝试将我的ui-keydown连接到身体,但由于它不是焦点,所以关键事件不会被触发.
例如:
<body ui-keydown="{'pageup':'nav_to($event, \'users\')'}">
Run Code Online (Sandbox Code Playgroud)
我知道我可以只关注一个div并将键绑定附加到那个但是当我有一个表单并且我想访问每个字段中的所有全局键绑定时会发生什么?
我们在公司使用瘦客户端,我们有很多用户使用同一个盒子.我按照以下网站上的说明安装了rbenv作为系统安装;
https://blakewilliams.me/posts/system-wide-rbenv-install
这归结为这些命令
cd /usr/local
git clone git://github.com/sstephenson/rbenv.git rbenv
chgrp -R staff rbenv
chmod -R g+rwxXs rbenv
Run Code Online (Sandbox Code Playgroud)
通过运行最后一行,我们应该能够像系统的任何用户一样安装gem,这是"staff"组的一部分.我们有两个开发人员是该组的一部分,他们都不能安装宝石.
我们得到错误;
~ % gem install cheat
/usr/local/rbenv/versions/2.3.5/lib/ruby/2.3.0/rubygems/config_file.rb:332:in `exist?': Insecure operation - exist? (SecurityError)
from /usr/local/rbenv/versions/2.3.5/lib/ruby/2.3.0/rubygems/config_file.rb:332:in `load_file'
from /usr/local/rbenv/versions/2.3.5/lib/ruby/2.3.0/rubygems/config_file.rb:198:in `initialize'
from /usr/local/rbenv/versions/2.3.5/lib/ruby/2.3.0/rubygems/gem_runner.rb:75:in `new'
from /usr/local/rbenv/versions/2.3.5/lib/ruby/2.3.0/rubygems/gem_runner.rb:75:in `do_configuration'
from /usr/local/rbenv/versions/2.3.5/lib/ruby/2.3.0/rubygems/gem_runner.rb:40:in `run'
from /usr/local/rbenv/versions/2.3.5/bin/gem:21:in `<main>'
~ % gem install cheat
Run Code Online (Sandbox Code Playgroud)
如果我从组中删除粘性位然后他们可以添加宝石,但如果有人试图删除由其他人安装的宝石,这将失败;
~ % chmod -R g-s rbenv
Run Code Online (Sandbox Code Playgroud)
如何允许多个用户从系统范围的rbenv安装中安装/卸载gem?
更新
/usr/local/rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems如您所见,这是目录中的安装示例
drwxrwxr-x 5 map7 map7 4.0K Jun 4 15:50 unicode-display_width-1.3.3
drwxrwxr-x 5 andre andre 4.0K May …Run Code Online (Sandbox Code Playgroud) 我有一台 CloudLinux 7.8(基于 CentOS 7)机器,我正在尝试将 postgresql11-devel 安装到系统上,但由于“llvm-toolset-7-clang >= 4.0.1”而失败。
这是完整的错误
[map7@ded94686 testapp]$ sudo yum install postgresql11 postgresql11-devel postgresql11-libs postgresql11-server
[sudo] password for map7:
Loaded plugins: fastestmirror, rhnplugin, universal-hooks
This system is receiving updates from CLN.
Loading mirror speeds from cached hostfile
* EA4: 101.0.120.94
* cpanel-addons-production-feed: 101.0.120.94
* cpanel-plugins: 101.0.120.94
* cloudlinux-x86_64-server-7: cl.mirror.serversaustralia.com.au
* epel: fedora.mirror.serversaustralia.com.au
Resolving Dependencies
--> Running transaction check
---> Package postgresql11.x86_64 0:11.8-1PGDG.rhel7 will be installed
---> Package postgresql11-devel.x86_64 0:11.8-1PGDG.rhel7 will be installed
--> Processing Dependency: llvm5.0-devel …Run Code Online (Sandbox Code Playgroud) 我一直在关注backbone.js的Railscast教程,我想扩展功能以包括键盘控制.我在节目视图中添加了以下内容:
class Raffler.Views.EntryShow extends Backbone.View
template: JST['entries/show']
events:
'click .back': 'showListing'
'keyup': 'goBack'
showListing: ->
Backbone.history.navigate("/", trigger: true)
goBack: (e) ->
console.log e.type, e.keyCode
render: ->
$(@el).html(@template(entry: @model))
this
Run Code Online (Sandbox Code Playgroud)
在我的节目模板上,我有以下内容:
<a href="#" class="back">Back</a>
<%= @entry.get('name') %></td>
Run Code Online (Sandbox Code Playgroud)
如果我使用tab键选择后退链接,然后开始点击随机键,我会在我的javascript控制台中输出.但是,如果我加载页面并且没有选择链接并且只是开始按键我在控制台中没有输出.
如何将事件绑定到文档,以便在加载屏幕时听到按下的任何键?
我刚刚开始在我的Rails应用程序中使用AngularJS,因为我习惯在Rails中使用haml模板,我想在客户端使用AngularJS.问题是我不知道在haml文件中的哪个位置读取.
我有一个投资者的模型,我正在尝试将'show'模板转换为haml,因为它是最容易开始的.
这是我关于show的AngularJS代码
investors.js.coffee
# Setup the module & route
angular.module("investor", ['investorService'])
.config(['$routeProvider', ($provider) ->
$provider
.when('/investors/:investor_id', {templateUrl: '/investors/show.html', controller: 'InvestorCtrl'})
])
.config(["$httpProvider", (provider) ->
provider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content')
])
angular.module('investorService', ['ngResource'])
.factory('Investor', ($resource) ->
return $resource('/investors/:investor_id.json', {}, {
show: {method: 'GET'},
})
)
angular.bootstrap document, ['investor']
Run Code Online (Sandbox Code Playgroud)
这是我的控制器AngularJS代码
investors_controller.js.coffee
# Show Investor
window.InvestorCtrl = ($scope, $routeParams, Investor) ->
html = haml.compileHaml({sourceId: 'simple'})
$('#haml').html(html())
investor_id = $routeParams.investor_id
$scope.investor = Investor.show({investor_id: investor_id})
Run Code Online (Sandbox Code Playgroud)
在后端我有一个Rails JSON API.
这是它读入的show.html文件
<script type="text/haml-template" id="simple">
%h1 {{investor.name}}
</script>
<div …Run Code Online (Sandbox Code Playgroud) 我正在使用Rails + AngularJS,并已切换到使用Protractor进行所有端到端测试.我使用protractor-rails gem设置它,这有助于我使用测试数据库而不是开发数据库进行测试.
问题是在我运行测试后,例如:'create_client_spec.js.coffee'然后我在我的表中留下了一个新的客户端,我的测试后没有清理它.
helper = require('../../helper.js.coffee')
describe('create a new client', ->
beforeEach ->
helper.login()
afterEach ->
helper.logout()
it 'shows the client after creation', ->
browser.get('/api#/clients')
element(By.id("new_btn")).click()
element(By.id("name")).sendKeys("John Smith")
element(By.id("create_btn")).click()
expect(element(By.id("heading")).getText()).toContain("John Smith")
)
Run Code Online (Sandbox Code Playgroud)
如何很好地清理这些测试?
我的一个想法是在afterEach中添加一个方法,以便在此文件中的每个测试后删除新客户端.
更新:
我把以下内容放在helper.js.coffee中
delete_client: ->
last=element.all(By.id("listing")).last()
last.element(By.id("delete")).click()
this.accept_dialog()
accept_dialog: ->
# Accept the dialog which is displayed
ptor = protractor.getInstance()
alertDialog = ptor.switchTo().alert()
alertDialog.accept()
Run Code Online (Sandbox Code Playgroud)
然后我在注销之前调用afterEach块中的helper.delete_client().它有效,但有更好的方法吗?
我一起使用AngularJS,ng-table和coffeescript,并希望在coffeescript中创建一个多模板过滤器并将其传递给我的angularjs模板.
我有一个名字和姓氏组合列,我想要两个过滤器'name'和'surname'.
到目前为止,我有这样的工作;
<td data-title="'Customer'" sortable="'fullname'"
filter="{'name_cont': 'text', 'surname_cont':'text'}" >
Run Code Online (Sandbox Code Playgroud)
但是我想在我的AngularJS控制器中定义这个过滤器
$scope.nameFilterDef = {
name: {
id: "text",
placeholder: "Name"
},
surname: {
id: "text",
placeholder: "Surname"
}
}
Run Code Online (Sandbox Code Playgroud)
并使用该过滤器清理我的模板;
<td data-title="'Customer'" sortable="'fullname'"
filter="nameFilterDef" >
Run Code Online (Sandbox Code Playgroud)
当我像这样调用过滤器时,虽然没有出现过滤器框.
更新
如果我在页面上放置{{nameFilterDef}},我可以看到我的过滤器哈希传入.
我有一个非常古老的Rails 2.3.18,ruby 1.9.3,rspec 1.x应用程序我们正在升级它并且它有restful-authentication.所以我用Devise 1.0.11取而代之.
我可以登录到该应用程序,但我的测试不会运行;
这是有问题的测试
require 'spec_helper'
describe CategoriesController do
context "As a logged in user" do
before do
login_user
current_firm = mock_model(Firm, :id => 1)
controller.stub!(:current_firm).and_return(current_firm)
end
describe "#index" do
it "should render index" do
get :index
response.should render_template('index')
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误;
NoMethodError in 'CategoriesController As a logged in user#index should render index'
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while …Run Code Online (Sandbox Code Playgroud) 我正在使用自动保存回原始文件作为我的组织模式,但我只希望它适用于此模式而不是其他任何东西.那很容易吗?
这是我的组织模式选项
;; Org-mode options
(add-hook 'org-mode-hook
'turn-on-visual-line-mode
'auto-save-mode)
(add-hook 'org-mode-hook '(lambda()
(setq auto-save-visited-file-name t)
(setq auto-save-interval 20)))
Run Code Online (Sandbox Code Playgroud)
注意:有关我的完整配置,请参阅https://github.com/map7/simple_emacs
angularjs ×4
coffeescript ×2
javascript ×2
angular-ui ×1
autosave ×1
backbone.js ×1
centos ×1
devise ×1
emacs ×1
end-to-end ×1
haml ×1
jasmine ×1
ngtable ×1
org-mode ×1
permissions ×1
postgresql ×1
protractor ×1
rbenv ×1
rspec ×1
ruby ×1
rubygems ×1
testing ×1