我正在为我的api构建一个2-legged OAuth提供程序.一切都正常连接,我可以从rails控制台进行签名调用.我遇到的问题是我无法将OAuth集成到controller_spec.
以下是我的服务器上的工作调用示例:
coneybeare $ rails c test
Loading test environment (Rails 3.2.0)
rails test: main
>> consumer = OAuth::Consumer.new("one_key", "MyString", :site => [REDACTED])
# => #<OAuth::Consumer:0x007f9d01252268 @key="one_key", @secret="MyString", @options={:signature_method=>"HMAC-SHA1", :request_token_path=>"/oauth/request_token", :authorize_path=>"/oauth/authorize", :access_token_path=>"/oauth/access_token", :proxy=>nil, :scheme=>:header, :http_method=>:post, :oauth_version=>"1.0", :site=>[REDACTED]}>
ruby: main
>> req = consumer.create_signed_request(:get, "/api/v1/client_applications.json", nil)
# => #<Net::HTTP::Get GET>
ruby: main
>> res = Net::HTTP.start([REDACTED]) {|http| http.request(req) }
# => #<Net::HTTPOK 200 OK readbody=true>
ruby: main
>> puts res.body
{"client_applications":[{"id":119059960,"name":"FooBar1","url":"http://test1.com"},{"id":504489040,"name":"FooBar2","url":"http://test2.com"}]}
# => nil
Run Code Online (Sandbox Code Playgroud)
以下是我在控制器测试中所做的事情:
require 'oauth/client/action_controller_request'
describe …Run Code Online (Sandbox Code Playgroud) 我在设置包中定义了我的Root.plist,它出现在设备设置中.现在,我希望它根据我构建项目的环境类型显示不同的选项.
我在XCode中定义了TEST和PROD方案(不同的构建配置),我希望为这些构建配置定义不同的Root.plist.如何才能做到这一点?
我们是否可以定义2个plist并使用不同的构建配置链接它们,或者我们可以在编译时根据所选的构建配置或方案修改root.plist.
请指教.
随着iPhone 5和其他armv7s设备的出现,现有的(闭源)第三方框架(如Flurry)存在兼容性问题,这些框架是在没有这种新架构的情况下构建的.
一种选择是等到他们发布一个新版本,但我希望可能有一个编译器标志或我可以在我的Xcode项目中使用的东西,让链接器知道不要期望这个框架的armv7s架构,并使用armv7代替.有这样的事吗?
我使用函数random()%x来生成随机数,但每次启动应用程序时,我都会看到它创建或生成相同的数字.
就像我根据随机数随机放置一些图像一样,无论我运行应用程序多少次,我都会看到所有图像都放在同一个地方.
我想在每张联系人照片周围添加边框.我有工作代码来创建这个有边框的图像和工作代码将其设置为联系人图像:
if (image) {
NSData *dataRef = UIImagePNGRepresentation(image);
CFDataRef cfdata = CFDataCreate(NULL, [dataRef bytes], [dataRef length]);
CFErrorRef error;
ret = ABPersonSetImageData(person, cfdata, &error);
if (ret) {
ret = ABAddressBookSave(addressBook, &error);
} else {
DebugLog(@"Could not write the image to the person: %@", [error description]);
}
CFRelease(cfdata);
}
Run Code Online (Sandbox Code Playgroud)
我看到的问题是,当在"联系人"或"电话"应用程序中查看时,边框图像在缩略图中正确显示,而来电显示的全屏图像则不然.
我原本以为它只是放大了一点,所以我尝试了边框大小.我确认边框在大镜头上根本没有显示.我错过了一些明显的东西吗
我正在创建一个拼贴与其他图像中的元素相结合.这是一些ASCII艺术来解释我在做什么:
Given images A, B and C,
AAA, BBB, CCC
AAA, BBB, CCC
AAA, BBB, CCC
I take part of A, part of B and part of C as columns:
Axx, xBx, xxC
Axx, xBx, xxC
Axx, xBx, xxC
...and combine them in one image like this:
ABC
ABC
ABC
where the first 1/3rd of the image is a colum of A's pic, the middle is a column of B's pic and the last is a column of C's pic. …Run Code Online (Sandbox Code Playgroud) 我有这个格式化的字符串,我正在翻译工作.
英语
"Check out the %1$@ %2$@ in %3$@: %4$@" = "Check out the %1$@ %2$@ in %3$@: %4$@"
德国翻译
"Check out the %1$@ %2$@ in %3$@: %4$@" = "Hör Dir mal %2$@ in %3$@ an: %4$@";
这些传递给一个[NSString stringWithFormat:]电话:
//////////////////////////////////////
// Share Over Twitter
NSString *frmt = NSLocalizedString(@"Check out the %1$@ %2$@ in %3$@: %4$@", @"The default tweet for sharing sounds. Use %1$@ for where the sound type (Sound, mix, playlist) will be, %2$@ for where the audio …Run Code Online (Sandbox Code Playgroud) 我的一些beta测试人员遇到了一个奇怪的崩溃,我遇到了麻烦.符号化的崩溃报告表明在init调用时,控制器作为单例进行简单分配时发生了崩溃,但是根据堆栈跟踪,我所看到的代码init实际上并不是崩溃所在的位置.这是相关代码:
1534| + (UA[REDACTED]PlayerController*)sharedInstance
1535| {
1536| @synchronized(self)
1537| {
1538| if (sharedInstance == nil)
1539| sharedInstance = [[UA[REDACTED]PlayerController alloc] init];
1540| }
1541| return sharedInstance;
1542| }
Run Code Online (Sandbox Code Playgroud)
这从未崩溃过,而且代码最近没有随时更改过.这是升高的堆栈跟踪:
Thread 5:
0 libSystem.B.dylib 0x33bd52d4 __kill + 8
1 libSystem.B.dylib 0x33bd52c4 kill + 4
2 libSystem.B.dylib 0x33bd52b6 raise + 10
3 libSystem.B.dylib 0x33be9d26 __abort + 62
4 libSystem.B.dylib 0x33be9d7e abort + 62
5 libSystem.B.dylib 0x33bd7980 __assert_rtn + 152
6 libgcc_s.1.dylib 0x32acab4e _Unwind_SjLj_Resume + 26
7 [REDACTED] 0x00060b64 +[UA[REDACTED]PlayerController sharedInstance] …Run Code Online (Sandbox Code Playgroud) 我有一个JSON和XML需要进行页面缓存基于API.我在api上设置了我的路由,将格式作为URL的一部分包含在内,这样URL就像这样工作:
http://example.com/foo/1/bar/2/xml
http://example.com/foo/1/bar/2/json
Run Code Online (Sandbox Code Playgroud)
我看到的问题是,在服务器的public文件夹中,文件被保存为xml.xml和json.json,这导致下次访问URL时缓存未命中.
有没有办法:
RAILS_ROOT/public/foo/1/bar/2/json).html适用于每个呼叫.(EX: RAILS_ROOT/public/foo/1/bar/2/json.html)这些中的任何一个都会导致我的服务器返回缓存文件而不是未命中.我怎样才能做到这一点?
编辑:
有人要求相关路线:
scope '(foo/:foo_id)', :foo_id => /\d+/ do
get '/bar/:bar_id/:format' => 'bars#show', :bar_id => /\d+/, :format => /json|xml|html/
end
Run Code Online (Sandbox Code Playgroud)
解决方案:
虽然我正在寻找一种使用内置页面缓存支持来实现这一目标的官方方法,但我最终只使用了后过滤器和我自己的页面缓存方法,如Anton所建议的那样
# application_controller.rb
def cache_api_page
if REDACTEDServer::Application.config.action_controller.perform_caching
self.class.cache_page(response.body, request.path, '')
puts "CACHED PATH: #{request.path}"
end
end
# bar_controller.rb
after_filter :cache_api_page, :only => [ :show, :index ]
Run Code Online (Sandbox Code Playgroud) 我有UTF-8字符串:Website • Facebook
这是中间的一个子弹aka •或0xE2 0x80 0xA2
该值正确存储在数据库中,并使用Rails 3和ruby 1.9.3使用默认设置在屏幕上正确显示.
我试图通过HTML电子邮件发送此信息,但当完成所有操作后,接收端会看到垃圾:

这背后的代码很简单,我有一个ActionMailer子类(默认情况下使用UTF-8)设置在布局中发送带有UTF-8内容编码的HTML电子邮件:
email.html.erb 布局文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="chrome=1,IE=9" />
<meta charset="utf-8">
<%= stylesheet_link_tag "application", :media => "all" %>
</head>
<body class='email'>
<%= yield %>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
内容使用相同的视图来呈现网页,重要的一行是:
<p><%= simple_format strip_tags(comment.text) %></p>
Run Code Online (Sandbox Code Playgroud)
我已经尝试了很多很多的排列force_encoding,encode,将多余的UTF-8编码的ActionMailer子类,视图文件和其他十几个事情,但没有顶部似乎工作.
通过Apple Mail 的原始html消息查看的重要HTML 是:
Website =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD Facebook
Run Code Online (Sandbox Code Playgroud)
如果您查看原始消息(上面链接),则不会在纯文本消息上发生这种情况,只会发生HTML消息.
TL; DR
ActionMailer正在替换应该是UTF-8项目符号:0xE2 0x80 0xA2
垃圾:0xEF 0xBF …
iphone ×5
ios ×2
xcode ×2
2-legged ×1
actionmailer ×1
addressbook ×1
caching ×1
clipping ×1
cocoa-touch ×1
core-data ×1
crash ×1
drawing ×1
encoding ×1
format ×1
image ×1
linker ×1
localization ×1
oauth ×1
objective-c ×1
random ×1
rspec ×1
ruby ×1
utf-8 ×1