我的webapp中有管理员和普通用户.我想根据他们的身份使他们的根(/)不同.从许多不同的页面访问根,所以如果我能在routes.rb文件中实现这一点会容易得多.这是我目前的档案.
ProjectManager::Application.routes.draw do
root :to => "projects#index"
end
Run Code Online (Sandbox Code Playgroud)
有人可以把我链接到一个可以告诉我进入方向的例子吗?有没有办法将逻辑放入路径文件?谢谢你的帮助.
我正在使用基本的karma/jasmine设置来测试我的Angular代码.这是我的测试:
var $controllerConstructor, ctr, mockSuperheroData, scope, deferred, q;
describe('main controller', function() {
var $controllerConstructor, ctr, mockSuperheroData, scope, deferred, q;
beforeEach(inject(function($controller, $rootScope, $q) {
scope = $rootScope.$new();
$controllerConstructor = $controller;
q = $q;
mockSuperheroData = {
getSuperheroes: function() {
deferred = q.defer();
return deferred.promise;
}
};
ctr = $controllerConstructor('MainCtrl', {$scope: scope, $location: {}, superheroService: mockSuperheroData, keys: {}});
}));
it('should set the result of getResource to scope.heroes', function() {
scope.getHeroes();
expect(scope.heroes).toBe(100);
});
}
Run Code Online (Sandbox Code Playgroud)
scope.getHeroes()调用mockSuperheroData.getSuperheroes()正在返回承诺的人.如何强制承诺在单元测试中返回我想要的内容?我在哪里可以接受嘲笑其回报的承诺?
我有一个字符串模板,目前看起来像这样:
var option = "\u00A0" + "\u00A0" + "\u00A0" + "\u00A0" + option.name;
Run Code Online (Sandbox Code Playgroud)
我正在尝试更改为新的ES6语法
var option = ` ${option.name}`
Run Code Online (Sandbox Code Playgroud)
但是当它出现在屏幕上时,ES6版本中没有任何空格,或者我指定它的字符串上没有4个空格缩进.这个问题在如使用这些字符串可能有一些与我options的select.有任何想法吗?
我有一个Observable我消耗另一个可观察的,但第二个Observable我无法解决.这是代码:
return Observable.fromPromise(axios(config))
.map(res => {
return {
accessToken: res.data.access_token,
refreshToken: res.data.refresh_token
}
})
.map(res => {
return {
me: getMe(res.accessToken),
accessToken: res.accessToken,
refreshToken: res.refreshToken
}
})
function getMe(accessToken) {
return Observable.fromPromise(axios.get({
url: 'https://api.spotify.com/v1/me',
}));
}
Run Code Online (Sandbox Code Playgroud)
该getMe函数返回一个Observable,但它永远不会被解析.我试图添加一个flatMap和一个concat,但它仍然没有解决.我该getMe如何解决?
我正在尝试按照本 Spring教程使用websockets.我webpack用来捆绑我的代码并将babel其转换ES6.我试图sockjs用一个正常的import声明来引入.
import SockJS from 'sockjs'
Run Code Online (Sandbox Code Playgroud)
但是在webpack运行时,我会丢失模块错误,
ERROR in ./~/stompjs/lib/stomp-node.js
Module not found: Error: Cannot resolve module 'net' in /Users/name/Developer/cubs-stack-4/cubs-webapp/node_modules/stompjs/lib
@ ./~/stompjs/lib/stomp-node.js 14:8-22
ERROR in ./~/websocket/package.json
Module parse failed: /Users/name/Developer/cubs-stack-4/cubs-webapp/node_modules/websocket/package.json Line 2: Unexpected token :
You may need an appropriate loader to handle this file type.
| {
| "_args": [
| [
| "websocket@latest",
@ ./~/websocket/lib/version.js 1:17-43
Run Code Online (Sandbox Code Playgroud)
主要是因为它有望继续运行Node.
我有两个问题.
首先,如何stompjs …
我的useEffect正在运行,但一旦完成,它就不会更新我的组件的状态。它总是显示以前的渲染。我以为我已经添加了所有适当的依赖项,但它仍然给了我陈旧的数据。这是我的钩子:
export default function useSort(items, sortKey, sortAscending) {
let [sorted, setSorted] = useState(items);
useEffect(() => {
let sortedItems = sortKey ? items.sort((a, b) => {
if (!a[sortKey] && b[sortKey]) return sortAscending ? -1 : 1;
if (a[sortKey] && !b[sortKey]) return sortAscending ? 1 : -1;
if (a[sortKey] > b[sortKey]) return sortAscending ? 1 : -1;
if (a[sortKey] < b[sortKey]) return sortAscending ? -1 : 1;
return 0;
}) : items;
setSorted(sortedItems);
}, [items, sortKey, sortAscending]);
return sorted;
} …Run Code Online (Sandbox Code Playgroud) 我正在使用一个名为Jquery Content Panel Switcher的Jquery插件.它完全符合标题所说的内容,它可以轻松切换div.页面的html是:
<!--The switcher buttons, basic anchor tags, with the switcher class -->
<a id="content1" class="switcher">One</a>
<a id="content2" class="switcher">Two</a>
<!-- The panel you wish to use to display the content -->
<div id="switcher-panel"></div>
<!-- The actual content you want to switch in and out of the panel, this is hidden -->
<div id="content1-content" class="switcher-content show"></div>
<div id="content2-content" class="switcher-content show"></div>
Run Code Online (Sandbox Code Playgroud)
在我的每个内容面板中,我都有一个表单.每种形式都有一张表:
<table class="table table-hover" data-controller="rank">
<thead>
<tr>
<th colspan="4" align="left"><h2>Rank 1</h2></th>
</tr>
<tr>
<th>Number</th>
<th>Requirements</th>
</tr>
</thead>
<tbody>
<tr …Run Code Online (Sandbox Code Playgroud) 我试图gulp在两个不同的项目中重用我的任务.我将我的gulp任务提取到父目录中,并尝试要求它们.这是我的目录结构.
parent/
gulp-tasks/
default.js
project1/
node_modules/
gulpfile.js
js/
project2/
node_modules/
gulpfile.js
js/
Run Code Online (Sandbox Code Playgroud)
这就是我gulpfile.js在每个项目中的所有内容
var requireDir = require('require-dir');
requireDir('../gulptasks');
Run Code Online (Sandbox Code Playgroud)
这是我的default.js样子:
var gulp = require('gulp');
gulp.task('default', function() {
//run code here
})
Run Code Online (Sandbox Code Playgroud)
当我尝试运行时gulp default,我得到的gulp是没有定义的.我知道node_modules在父目录中没有,但有没有办法指向node_modules每个子项目?我不是特别想要一个关于gulp的答案但是如何构建我的项目以使我的代码可重用?
我正在显示一行图像.这是我的html:
<div class="flex">
<img src="img1.jpg"/>
<img src="img2.jpg"/>
<img src="img3.jpg"/>
<img src="img4.jpg"/>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的css:
.flex {
display: flex
}
img {
height: auto;
}
Run Code Online (Sandbox Code Playgroud)
我想让我的图像连续显示.我没有给你任何img小号任何宽度,等等Chrome的img.就拿他们的自然宽比,然后屏幕推出更大.这就是我希望它的工作方式.有了Safari,它们flexbox只会占据整个viewport宽度.我已经尝试设置图像宽度,flex-basis,但不能Safari仅仅使用可见屏幕.有一个flexbox我不知道的问题吗?我还可以做些什么?
我有一个svg包裹在中的span。该svg有一组height和width的15px。
<span>
<svg xmlns="http://www.w3.org/2000/svg" id="remove-circle" viewBox="0 0 1200 1200.0071" width="15px" height="15px"><path d="..."/></svg>
</span>
Run Code Online (Sandbox Code Playgroud)
我包裹svg在一个span让我可以更容易地定位它,但后来它有一个height的19px。我曾尝试将设置line-height为0,但没有任何改变。要使span尺寸与相同,我该svg怎么做?
javascript ×5
angularjs ×1
css ×1
css3 ×1
ecmascript-6 ×1
flexbox ×1
gulp ×1
html ×1
html5 ×1
jasmine ×1
jquery ×1
node-modules ×1
node.js ×1
promise ×1
react-hooks ×1
reactjs ×1
routing ×1
rxjs ×1
stompjs ×1
unit-testing ×1