所以我听说在没有"var"的情况下初始化的js中的变量将是全局变量.所以:
$(document).ready(function(){
function foo(){
//since i'm not using "var", will this function become global?
}
var bar = function(){
//is this the better way to declare the function?
}
})
Run Code Online (Sandbox Code Playgroud)
如果它是全局的,为什么我无法在控制台中访问它.如果它不是全局的,并且它的范围在函数中,那么省略"var"会花费一些性能吗?谢谢.
我在Laravel BaseController中有以下代码.我想Authorization用带有令牌的标头来保护我的所有api资源.
public function __construct()
{
$this->beforeFilter('@getUserFromToken');
}
public function getUserFromToken($route, $request)
{
$accessToken = Request::header('Authorization');
if(!empty($accessToken)){
$this->currentUser = User::findByToken($accessToken);
}else{
return Request::header('Authorization'); //THE PROBLEM
return Response::json(['error'=>'Not authorized. Access token needed in Header.Authorization'], 403);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的.htaccess,如果这是相关的.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
因此,如果我有标记的问题行,Apache将完美地读取所有内容.我会得到我的回复,而不是得到403.但是,如果我没有该行,我将收到403自定义错误消息的错误.为什么?显然我使用相同的代码$this->currentUser = User::findByToken($accessToken);,为什么通过留下标记线我将能够得到标题?是否在场景后面发生重定向, …
为什么会这样
@discussions = Discussion.where(:discussable => @discussable)
Run Code Online (Sandbox Code Playgroud)
不起作用.然而这项工作:
@discussions = Discussion.where(:discussable_id => @discussable.id, :discussable_type => @discussable.class.to_s)
Run Code Online (Sandbox Code Playgroud)
谢谢.
那么为什么呢?很困惑......谢谢!
$('#navigation ul li a:first').index($('#navigation ul li a')) >> returns 0 expect 0
$('#navigation ul li a:last').index($('#navigation ul li a')) >> returns -1 expect 19
$('#navigation ul li a').eq(2).index($('#navigation ul li a')) >> returns -1 expect 2
更新:这里有一些HTML,这是我的分页代码:
<div id="navigation">
<ul>
<li><a class="current" href="#1-1">1</a></li>
<li><a class="" href="#1-2">2</a></li>
<li><a class="" href="#1-3">3</a></li>
<li><a class="" href="#1-4">4</a></li>
<li><a class="" href="#1-5">5</a></li>
<li><a class="" href="#1-6">6</a></li>
<li><a class="" href="#1-7">7</a></li>
<li><a class="" href="#1-8">8</a></li>
<li><a class="" href="#1-9">9</a></li>
<li><a class="" href="#1-10">10</a></li>
<li><a class="" href="#1-11">11</a></li>
<li><a class="" href="#1-12">12</a></li>
<li><a class="" href="#1-13">13</a></li> …Run Code Online (Sandbox Code Playgroud) 在rspec中使用Capybara测试javascript警报.为什么
expect{
click_link "Cancel my account"
page.driver.browser.switch_to.alert.accept
}.to change(User, :count).by(-1)
Run Code Online (Sandbox Code Playgroud)
失败.然而
puts User.count
expect{
click_link "Cancel my account"
page.driver.browser.switch_to.alert.accept
puts User.count
}.to change(User, :count).by(-1)
Run Code Online (Sandbox Code Playgroud)
没有?我该如何修复测试?没有reload功能User
<p><a href="http://vimeo.com/23486376" title="Rebecca Black's Friday on Rock Band"><img src="http://b.vimeocdn.com/ts/152/946/152946954_200.jpg" alt="Rebecca Black's Friday on Rock Band" /></a></p><p></p><p>Cast: <a href="http://vimeo.com/thenerdery" style="color: #2786c2; text-decoration: none;">The Nerdery</a></p>
Run Code Online (Sandbox Code Playgroud)
我有一个像上面的字符串,我想知道Objective-c中获得"http://b.vimeocdn.com/ts/152/946/152946954_200.jpg"子字符串的最佳方法是什么?NSScanner?NSString方法?谢谢!
更新:字符串实际上是:
<p><a href="http://vimeo.com/23333305" title="Ad League Bowling Championship"><img src="http://b.vimeocdn.com/ts/151/787/151787049_200.jpg" alt="Ad League Bowling Championship" /></a></p><p></p><p>Cast: <a href="http://vimeo.com/thenerdery" style="color: #2786c2; text-decoration: none;">The Nerdery</a></p>
Run Code Online (Sandbox Code Playgroud) 所以这是我从ActiveRecord中检索到的一个对象 other = [#<Referrer id: 16, name: "Other", published: true, created_at: "2011-07-11 16:22:00", updated_at: "2011-07-11 16:22:00">]
为什么other.created_at我不能这样做other.name呢?
这是模型:
class Referrer < ActiveRecord::Base
end
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
NoMethodError: undefined method `created_at' for #<ActiveRecord::Relation:0x1035763c8>
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
有人能告诉我如何解析这个字符串
来自:Dela(deal@gmail.com)致:Roger(perter@gmail.com)日期:10月11日星期一主题:关于艾玛
并将其存储为哈希,如:
{:from=> "Dela(deal@gmail.com)", :to=>"Roger(perter@gmail.com)", :date=>"Monday, Oct 11", :subject=>"about emma"}
Run Code Online (Sandbox Code Playgroud) 我该怎么做?这些不起作用:
if(empty($_FILES)){
echo "there is no file uploaded";
exit;
} else {
echo "there is file";
}
if(sizeof($_FILES)!=0){
echo "there is file";
} else {
echo "there is no file";
}
Run Code Online (Sandbox Code Playgroud) activerecord ×2
javascript ×2
php ×2
ruby ×2
apache ×1
capybara ×1
cocoa ×1
coding-style ×1
forms ×1
iphone ×1
jquery ×1
laravel ×1
objective-c ×1
parsing ×1
rspec ×1
string ×1
tdd ×1