我to_json在一个对象上使用该方法,并试图让:methods参数工作.我的模型(Drop)上有一个方法叫做is_favorited_by_user?.此方法接受一个参数current_user,然后检查用户是否收到了drop.如何通过该to_json方法传递此参数.
render :json => @drops.to_json(:methods => :is_favorited_by_user?(current_user))
Run Code Online (Sandbox Code Playgroud) 我有一个可以向上滑动的ViewController.单击"保存"时,它会向服务器发送请求.请求完成后,它会关闭ViewController.我将NSURLConnection切换到使用async和blocks(https://github.com/rickerbh/NSURLConnection-Blocks).解除ViewController现在抛出"线程2:程序接收信号:EXC_BAD_ACCESS".如果重要的话,我正在使用ARC.
- (IBAction) savePressed
{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://api.com/items/create"]];
//NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[NSURLConnection asyncRequest:request success:^(NSData *data, NSURLResponse *response) {
[self close];
} failure:^(NSData *data, NSError *error) {
[self close];
}];
}
- (void) close
{
[self dismissViewControllerAnimated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
这是日志
2012-10-24 10:32:43.780 Prayrbox[22268:1703] bool _WebTryThreadLock(bool), 0x1f21fd90: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit …Run Code Online (Sandbox Code Playgroud)