当我跑:
ruby -I test test/unit/job_test.rb
Run Code Online (Sandbox Code Playgroud)
从应用程序根目录,我收到以下错误:
.../app/models/name_position.rb:9:in `<class:NamePosition>':
uninitialized constant NamePosition::PositionManager (NameError)
from .../app/models/name_position.rb:1:in `<top (required)>'
from .../app/models/ac_buyer.rb:1:in `<top (required)>'
...
Run Code Online (Sandbox Code Playgroud)
这是相关代码:
# app/models/ac_buyer.rb
class AcBuyer < NamePosition
end
# app/models/name_position.rb
class NamePosition < ActiveRecord::Base
...
include PositionManager
end
# lib/position_manager.rb
module PositionManager
...
end
Run Code Online (Sandbox Code Playgroud)
看起来在运行测试时,lib目录中的文件不会自动加载.
有什么建议 ?
我在我的页面中进行了以下登录检查:
class LoungeController < ApplicationController
before_filter :confirm_logged_in
def index
end
end
Run Code Online (Sandbox Code Playgroud)
虽然confirm_logged_in在这里定义:
class ApplicationController < ActionController::Base
protect_from_forgery
protected
def confirm_logged_in
return true if current_user
redirect_to(:controller => 'access', :action => 'login')
return false # halts the before_filter
end
def current_user
return false unless session[:user_id]
user = User.find(session[:user_id])
return false unless user
(user.display_name == session[:user_display_name]) ? user : nil
end
end
Run Code Online (Sandbox Code Playgroud)
现在,我想用confirm_logged_in的也是app/views/layouts/application.html.erb:
<% if confirm_logged_in %>
<div id="logged_in_as">You are logged in as <%= session[:user_display_name] %></div>
<div …Run Code Online (Sandbox Code Playgroud) 请考虑以下示例:
HTML:
<div class="wrapper">
<div class="left">Some text here</div><div class="right">Hello Stack Overflow</div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.wrapper {
border: 1px solid black;
width: 400px;
}
.left {
border: 1px solid green;
display: inline-block;
}
.right {
border: 1px solid red;
display: inline-block;
float: right;
}
Run Code Online (Sandbox Code Playgroud)
我想div根据红色的宽度强制绿色的宽度尽可能大.红色的宽度div可根据div内容而变化.因此,例如,如果红色的宽度div为150px,则绿色的宽度应为250px.这应该总是如此:
green div width + red div width = 400px
Run Code Online (Sandbox Code Playgroud)
我怎么能用CSS实现这个目标?
没有Javascript请...
给定一个函数名作为字符串,我如何确定这个函数是否存在(全局),如果是,则调用此函数?
我试着这样做:
function foo() {
alert("foo called");
}
var func_name = "foo";
if (typeof window[func_name] == 'function') {
foo();
} else {
alert(func_name + " is not defined!");
}
Run Code Online (Sandbox Code Playgroud)
我的.gitignore文件看起来像这样:
> cat .gitignore
.bundle
db/*.sqlite3
log/*.log
tmp/**/*
*~
Run Code Online (Sandbox Code Playgroud)
但是,git不会忽略以下结尾的文件~:
> git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: app/views/jobs/_form.html.erb
# modified: app/views/jobs/_form.html.erb~
# modified: public/stylesheets/jobs_new_edit.css~
Run Code Online (Sandbox Code Playgroud)
这可能是什么原因?
考虑以下示例:( 现场演示)
HTML:
<div>
<p>
<strong>Stack</strong>
<span>Overflow</span>
</p>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
p {
background-color: #aaa;
}
span {
background-color: #777;
}
Run Code Online (Sandbox Code Playgroud)
我怎么能让<span>宽度成为所有可用空间?
注意: <strong>并且<span>应该在同一行.
任何人都可以解释为什么前两个按钮组工作,但第三个按钮组不工作?
<div class="btn-group">
<button ng-repeat="company in companies"
class="btn"
ng-model="radioModel.id"
btn-radio="company.id">
{{company.name}}
</button>
</div>
<div class="btn-group">
<button class="btn btn-two"
ng-model="radioModel.id"
btn-radio="2">
two
</button>
<button class="btn btn-two"
ng-model="radioModel.id"
btn-radio="3">
three
</button>
</div>
<div class="btn-group">
<button ng-repeat="company in companies"
class="btn btn-{{ company.name }}"
ng-model="radioModel.id"
btn-radio="company.id">
{{company.name}}
</button>
</div>
Run Code Online (Sandbox Code Playgroud)
$scope.companies = [ { id: 2, name: "two"}, {id: 3, name: "three"} ];
$scope.radioModel = { id: 3 };
Run Code Online (Sandbox Code Playgroud)
此示例使用AngularUI Bootstrap 0.5.0.如果我将其更改为0.3.0,一切都按预期工作.
arr 在给定目标索引数组的情况下,如何对给定数组进行排序ind?
例如:
var arr = ["A", "B", "C", "D", "E", "F"];
var ind = [ 4, 0, 5, 2, 1, 3 ];
rearrange(arr, ind);
console.log(arr); // => ["B", "E", "D", "F", "A", "C"]
arr = ["A", "B", "C", "D"];
ind = [ 2, 3, 1, 0 ];
rearrange(arr, ind);
console.log(arr); // => ["D", "C", "A", "B"]
Run Code Online (Sandbox Code Playgroud)
我尝试了以下算法,但在上面的第二个例子中失败了.
function swap(arr, i, k) {
var temp = arr[i];
arr[i] = arr[k];
arr[k] = temp;
}
function …Run Code Online (Sandbox Code Playgroud)