我试图从Devise中覆盖destroy方法SessionsController
,但我还没有成功.我已经为该create
方法完成了它,但我不知道为什么它不适用于该destroy
方法.
这是我的SessionsController
:
module Api
module V1
class SessionsController < Devise::SessionsController
skip_before_filter :verify_authenticity_token, if: :json_request?
def create
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#failure")
resource.update_token
sign_in_and_redirect(resource_name, resource)
end
def sign_in_and_redirect(resource_or_scope, resource=nil)
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource ||= resource_or_scope
sign_in(scope, resource) unless warden.user(scope) == resource
return render :json => {:success => true}
end
# DELETE /resource/sign_out
def destroy
puts "DELETE /resource/sign_out"
return render :json => {:success => true}
end
def failure
return render :json …
Run Code Online (Sandbox Code Playgroud) 我有一个问题,使用SDWebImage将图像加载到自定义UITableViewCell内的UIImageView.这是我在UITableView委托中的代码:
static NSString *userTableId = @"userTableId";
UserDetailsTableViewCell *cell = (UserDetailsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:userTableId];
NSDictionary *user = [userList objectAtIndex:indexPath.row];
NSInteger position = indexPath.row + 1;
[cell.userDetailsView loadFromDictionary:user WithIndex:position ForCharitie:false];
cell.userDetailsView.delegate = self;
cell.userDetailsView.delegate = self;
return cell;
Run Code Online (Sandbox Code Playgroud)
这是我的loadFromDictionary代码:
-(void) loadFromDictionary: (NSDictionary *) dic WithIndex: (NSInteger) index ForCharitie: (BOOL) isCharitie{
NSDictionary *userImageDic = [dic objectForKey:@"image"];
NSString *url =[userImageDic objectForKey:@"url"];
[userImage setImage:[UIImage imageNamed:@"defaultAvatar"]];
if ([url class] != [NSNull class]){
[userImage setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"defaultAvatar"]];
}
}
Run Code Online (Sandbox Code Playgroud)
现在,问题是如果我在一些图像完成加载之前向下滚动.例如,假设我看到前8行,第1,2和3行仍然加载他们的图像,现在我滚动到9-16,我看到了defaultAvatar
所有这些,并在几秒后(我猜图像时)第1,2和3行完成下载),单元格9,10和11上的图像变为属于1,2和3的图像.我不知道是否有办法阻止图像下载时我重用了这个细胞,或类似的东西.谢谢你,对不起我的英文!
因为我正在学习语言,所以我正在和Haskell一起玩,而我发现了一些我不理解的东西,我找不到解释.如果我尝试运行此代码:
map (`div` 0) [1,2,3,4]
Run Code Online (Sandbox Code Playgroud)
我得到除以0的异常,这是预期的.但是,如果我运行此代码:
length (map (`div` 0) [1,2,3,4])
Run Code Online (Sandbox Code Playgroud)
我得到4!
我想知道为什么当我在长度函数内部进行映射时,我没有得到除以0的异常!
我正在学习Haskell,我遇到了一些我无法理解的东西,我无法找到解释.所以,我在无限列表上测试了一些函数,看看它们是如何工作的,我发现了地图和滤波器之间的差异,我想了解一下.
Prelude.map
定义:
map _ [] = []
map f (x:xs) = f x : map f xs
Run Code Online (Sandbox Code Playgroud)
Prelude.filter
定义:
filter _pred [] = []
filter pred (x:xs)
| pred x = x : filter pred xs
| otherwise = filter pred xs
Run Code Online (Sandbox Code Playgroud)
如果我运行这个:
map (==5) [1..]
Run Code Online (Sandbox Code Playgroud)
输出开始,它永远不会结束,直到我停止它.因为列表是无限的,所以很有意义.
但现在如果我运行这个:
filter (==5) [1..]
Run Code Online (Sandbox Code Playgroud)
我什么也看不见,甚至没有[5,
.这也是有道理的,因为列表也是无限的,但是我想要了解beetwen map和filter的区别是什么.谢谢你,对不起我的英文!
编辑:我使用的是tryhaskell.org,这就是问题所在!
我有以下代码,我已经尝试了多种方法来编写它,但我不能使它工作.我需要的是if
在do
块内使用条件.
palin :: IO ()
palin
= do line <- getLine
putStr line
if True
then putStr line
Run Code Online (Sandbox Code Playgroud)
我将条件更改为true只是为了让它更容易.我尝试添加else
句子,但我也一样.
我遇到了方法定义的问题.我在"购买"模型中有这个代码:
def update_amount newamount
self.total_amount = self.total_amount +newamount
end
Run Code Online (Sandbox Code Playgroud)
这个代码在其他地方:
buy.update_amount(amount)
Run Code Online (Sandbox Code Playgroud)
如果我运行该程序,我会收到此错误:
ArgumentError (wrong number of arguments (1 for 0)):
app/models/buy.rb:18:in `update_amount'
Run Code Online (Sandbox Code Playgroud)
现在,如果我为此改变(只是为了尝试):
buy.update_amount
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
ArgumentError (wrong number of arguments (0 for 1)):
app/models/buy.rb:18:in `update_amount'
Run Code Online (Sandbox Code Playgroud)
我是Ruby on Rails的新手,所以它可能很简单.
我正在学习一些Haskell而我无法理解.我有这个表达式:
flip foldr id
Run Code Online (Sandbox Code Playgroud)
我需要找到它的类型.经过很长一段时间试图解决这个问题,我放弃了并查找了正确的答案,即:
(a -> (a1 -> a1) -> a1 -> a1) -> [a] -> a1 -> a1
Run Code Online (Sandbox Code Playgroud)
但我不明白为什么,我想!我想这[a] -> a1 -> a1
来自foldr
表达,但我不知道如何继续.谢谢你,对不起我的英文!