我需要在向API发送请求时对客户端进行身份验证.客户端有一个API令牌,我正在考虑使用标准Authorization头将令牌发送到服务器.
通常,此标头用于Basic和Digest身份验证.但我不知道是否允许自定义此标头的值并使用自定义身份验证方案,例如:
Authorization: Token 1af538baa9045a84c0e889f672baf83ff24
Run Code Online (Sandbox Code Playgroud)
你会推荐这个吗?或者是否有更好的方法来发送令牌?
我读了一些关于这些论点的文件,但我不清楚它们是什么,它们之间有什么区别,如果其中一个符合我的需要.
我需要编写一个可插入其他应用程序的应用程序,并希望将其作为gem包含在其他应用程序中.基本上我需要一些模型,一个控制器和没有视图,加上一些初始化,支持来自托管应用程序和生成器的配置参数.
我是正确的吗?
我应该阅读什么才能理解如何做到这一点?
更新:
有很多细节AF一个很不错的文章,可以发现在这里.
实质上:
Railtie是Rails框架的核心,它提供了几个钩子来扩展Rails和/或修改初始化过程.
Rails :: Engine只不过是一个已经设置了一些初始化程序的Railtie.由于Rails :: Application和Rails :: Plugin是引擎,因此这里描述的相同配置可以在所有三个中使用.
我正在跟随斯坦福机器学习课程.Andrew Ng和我想开始在ruby中实现这些例子.
是否有任何框架/ gems/libs /现有代码在ruby中接近机器学习?我发现了一些与此相关的问题和一些项目,但似乎已经很老了.
我按照omniauth的轨道演员创建了twitter的身份验证(http://railscasts.com/episodes/235-omniauth-part-1?view=comments).它在开发中工作正常但我无法让rspec检测到我已经创建了身份验证.这是我的身份验证控制器中创建功能的代码段:
def create
begin
auth_hash = request.env["omniauth.auth"]
@auth = current_user.authentications.build( :provider => auth_hash['provider'],
:uid => auth_hash['uid'],
:name => auth_hash['user_info']['name'],
:nickname => auth_hash['user_info']['nickname'],
:image => auth_hash['user_info']['image']
)
if @auth.provider.downcase == "twitter"
@auth.auth_token = auth_hash['credentials']['token']
@auth.secret_token = auth_hash['credentials']['secret']
@auth.site = auth_hash['user_info']['urls']['Twitter']
elsif @auth.provider == "Facebook"
end
rescue
redirect_to current_user, :flash => { :error => "Missing oauth data!! Check with administrator!"}
else
if @auth.save
msg = "Authentication success"
else
msg = "Already have authentication"
end
redirect_to current_user, :notice => msg
end …Run Code Online (Sandbox Code Playgroud) 学习新语言的最佳方法是阅读结构良好且记录完备的项目,这些项目以正确的方式使用语言结构.
什么是最好的clojure回购阅读和从中学习?
在制作Passenger-Monit插件时,我认为使用初始化器是最合适的,即
module PassengerMonit
class Railtie < Rails::Railtie
initializer "my_plugin.some_init_task" do
# my initialization tasks
end
end
end
Run Code Online (Sandbox Code Playgroud)
但是,由于某种原因,块中的代码从未执行过.我终于做了一个解决方案
config.before_initialize {}
Run Code Online (Sandbox Code Playgroud)
但我很好奇,为什么初始化程序没有被执行.有什么可以阻止它运行?
我正在玩ruby的元编程功能,我发现它有点毛茸茸.我正在尝试使用模块包装方法调用.目前,我这样做:
module Bar
module ClassMethods
def wrap(method)
class_eval do
old_method = "wrapped_#{method}".to_sym
unless respond_to? old_method
alias_method old_method, method
define_method method do |*args|
send old_method, *args
end
end
end
end
end
def self.included(base)
base.extend ClassMethods
end
end
class Foo
include Bar
def bar(arg = 'foo')
puts arg
end
wrap :bar
end
Run Code Online (Sandbox Code Playgroud)
三个问题:
有没有办法在不重命名方法的情况下这样做,以便允许使用super?还是更清洁/更短的东西?
有没有一种干净的方法来设置默认值?
有没有办法wrap :bar进一步推动通话?
我是PowerPoint VBA的新手,请耐心等待.
我想要:
到目前为止,我已经能够完成前3个任务,但我需要最后2个帮助.这是我的代码:
Sub test()
Dim slide As Object
Dim shape As Object
Dim shapeNames As Object
Dim chSeries As Series
i = 0
For Each slide In ActivePresentation.Slides
For Each shape In slide.Shapes
If shape.HasChart Then
i = i + 1
Debug.Print "found a chart on slide", i
End If
Next
Next
End Sub
Run Code Online (Sandbox Code Playgroud) 我想用 Faker 为数据库做种,问题是我在执行以下操作时遇到错误:
rake db:reset
Run Code Online (Sandbox Code Playgroud)
我收到这条消息:
rake aborted!
I18n::MissingTranslationData: translation missing: en.faker.name.name
/Library/Ruby/Gems/2.0.0/gems/i18n-0.7.0/lib/i18n.rb:311:in `handle_exception'
/Library/Ruby/Gems/2.0.0/gems/i18n-0.7.0/lib/i18n.rb:161:in `translate'
/Library/Ruby/Gems/2.0.0/gems/faker-1.4.3/lib/faker.rb:128:in `rescue in translate'
/Library/Ruby/Gems/2.0.0/gems/faker-1.4.3/lib/faker.rb:120:in `translate'
/Library/Ruby/Gems/2.0.0/gems/faker-1.4.3/lib/faker.rb:86:in `fetch'
/Library/Ruby/Gems/2.0.0/gems/faker-1.4.3/lib/faker.rb:99:in `parse'
/Library/Ruby/Gems/2.0.0/gems/faker-1.4.3/lib/faker/name.rb:8:in `name'
/Users/hbendev/code/wikitec/db/seeds.rb:6:in `block in <top (required)>'
/Users/hbendev/code/wikitec/db/seeds.rb:4:in `times'
/Users/hbendev/code/wikitec/db/seeds.rb:4:in `<top (required)>'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `block in load'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
/Library/Ruby/Gems/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:547:in `load_seed'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:250:in `load_seed'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:180:in `block (2 levels) in <top (required)>'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:139:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:setup => db:seed
Run Code Online (Sandbox Code Playgroud)
我不知道为什么会出现这个错误,因为我之前对 Faker 没有任何问题,我只是想重置数据库以更新种子。
我谷歌它,但我找不到任何相关的解决问题的方法。
我尝试添加:
I18n.reload!
Run Code Online (Sandbox Code Playgroud)
之后require …
这个问题是Facebook的扩展版本实时更新不会调用我们的服务器,这似乎已经死了.另外,使用Koala实时更新Heroku上的内部服务器错误没有帮助,因为我正在从heroku控制台订阅pjaspers建议.
我有一个应用程序(ruby 1.9.2p290和Rails 3.1.3)连接到Facebook以从当前用户获取数据.考拉宝石(v1.2.1)一切正常,但我每次用户登录时都会轮询fb服务器.我想使用facebook实时更新,我已阅读以下内容:
我已经在测试模式下设置了系统并成功部署到了heroku.我可以订阅用户对象,我得到了我的服务器的GET请求,但是没有收到来自Facebook的更新信息的POST.如果我手动向我的服务器发出POST,一切正常.
更多信息:routes.rb
get '/realtime' => 'realtime#verify'
post '/realtime' => 'realtime#change'
Run Code Online (Sandbox Code Playgroud)
发电
realtime GET /realtime(.:format) {:controller=>"realtime", :action=>"verify"}
POST /realtime(.:format) {:controller=>"realtime", :action=>"change"}
Run Code Online (Sandbox Code Playgroud)
控制器(模拟版本,仅测试它是否正常工作):
class RealtimeController < ApplicationController
def verify
render :text => params["hub.challenge"]
end
def change
puts params.inspect
render :nothing => true
end
end
Run Code Online (Sandbox Code Playgroud)
来自heroku控制台的订阅:
irb(main):004:0> @updates = Koala::Facebook::RealtimeUpdates.new(:app_id => ENV['FACEBOOK_APP_ID'], :secret => ENV['FACEBOOK_APP_SECRET'])
=> #<Koala::Facebook::RealtimeUpdates:0x00000004f5bca8 …Run Code Online (Sandbox Code Playgroud) railtie ×2
ruby ×2
algorithm ×1
api ×1
bloc.io ×1
charts ×1
clojure ×1
facebook ×1
faker ×1
frameworks ×1
heroku ×1
http ×1
http-headers ×1
initializer ×1
loops ×1
omniauth ×1
powerpoint ×1
rails-i18n ×1
real-time ×1
rest ×1
rspec ×1
vba ×1