我想做一个upsert.Rails还不支持这个.查询是这样的:
INSERT INTO foos (thing_id, bar_id) VALUES (1, 2)
ON CONFLICT (thing_id, bar_id) DO NOTHING
Run Code Online (Sandbox Code Playgroud)
我可以用self.class.connection.execute或轻松做到这一点exec_insert.但我也希望利用准备好的陈述.我以为我可以这样做:
thing_id = ActiveRecord::Relation::QueryAttribute.new("thing_id", thing.id, ActiveRecord::Type::Integer.new)
bar_id = ActiveRecord::Relation::QueryAttribute.new("bar_id", id, ActiveRecord::Type::Integer.new)
self.class.connection.exec_insert(<<-SQL, nil, [thing_id, bar_id])
INSERT INTO foos (thing_id, bar_id) VALUES ($1, $2)
ON CONFLICT (thing_id, bar_id) DO NOTHING
SQL
Run Code Online (Sandbox Code Playgroud)
但是当我试验这个时,似乎没有创建一个准备好的语句.
我试过这种风格:
query = <<-SQL
INSERT INTO foos (thing_id, bar_id) VALUES ($1, $2)
ON CONFLICT (thing_id, bar_id) DO NOTHING
SQL
connection = ActiveRecord::Base.connection.raw_connection
connection.prepare('some_name', query)
st = connection.exec_prepared('some_name', [ …Run Code Online (Sandbox Code Playgroud) 我想authogic永远不会设置user_credentialscookie,只使用标准的Rails会话cookie.
我看到Session包含在Authlogic::Session::Session::Base之后Cookies.如果我登录我的应用程序然后删除user_credentialscookie,我仍然保持登录状态.所以显然authlogic是在两个地方存储凭据并检查这两个地方?或忽略cookie但仍然设置它?我怎么能让它从未设置或引用user_credentialscookie?
我正在组建一个rails部署,其中公共目录是系统上另一个目录的符号链接.这是nginx .8上的乘客3.它似乎不喜欢这种设置.默认情况下,Nginx总是遵循符号链接,所以AFAIK不是做与Apache的+ FollowSymLinks等效的事情.
更新
看起来这里包括:http://www.modrails.com/documentation/Users%20guide%20Nginx.html#application_detection
请注意,Nginx的Phusion Passenger不会解析根路径中的任何符号链接.例如,假设您的根指向/home/www/example.com,而后者又是/webapps/example.com/public的符号链接.Nginx的Phusion Passenger将检查/home/www/config/environment.rb,而不是/webapps/example.com/config/environment.rb.此文件当然不存在,因此Phusion Passenger不会为此虚拟主机激活自身,并且您很可能会看到Nginx默认目录处理程序生成的某些输出,例如Forbidden错误消息.
Rack应用程序的检测通过相同的机制进行,Phusion Passenger将寻找config.ru而不是config/environment.rb.
所以我想知道是否有一些适当的配置符号可以解决这个问题.
在我的应用程序中,我有
class User
include User::Foo
end
Run Code Online (Sandbox Code Playgroud)
User::Foo 在app/models/user/foo.rb中定义
现在我正在使用一个定义自己的Foo类的库.我收到这个错误:
警告:toplevel User :: Foo引用的常量Foo
User仅指Foo完整路径User::Foo,并且Foo从不实际引用Foo.
这是怎么回事?
更新:记得以前我遇到过同样的问题,在问题1中看到:如何在ruby中引用子模块的"完整路径"?
我从分支大师开始并开发.我根据开发制作了分支foo.7稍后提交,现在我意识到我希望我从主人那里取消.我可以挑选每个提交,没什么大不了的,但是有一个更流畅的方式吗?
在我的路线文件中,我有:
resources :subscription, :only => [:show], :constraints => {:protocol => "https"}
Run Code Online (Sandbox Code Playgroud)
我正在尝试为此路线添加一个规范,如下所示:
it "recognizes and generates #show" do
{ :get => "/subscription", :protocol => 'https' }.should route_to(:controller => "subscriptions", :action => "show")
end
Run Code Online (Sandbox Code Playgroud)
但是,规范仍然失败.如果我删除了:protocol => 'https',规范也失败了:
ActionController::RoutingError: No route matches "/subscription"
哪个WSGI框架超轻量级且极小?如果你熟悉ruby,那么我正在寻找类似于Rails Metal的东西.
在Kindle Fire上运行我的网站时,我遇到了一些不同的javascript行为,而不是Chrome.为了调试这个,我需要访问Chrome Developer Tool或Firebug之类的东西.有什么建议?
本文提到了4种在ruby 1.9中调用proc的方法,而===就是其中之一.我不明白为什么会这样做.它是否与===的正常含义有任何关系(询问这两个对象是否是同一个对象)?
irb(main):010:0> f =-> n {[:hello, n]}
=> #
irb(main):011:0> f.call(:hello)
=> [:hello, :hello]
irb(main):012:0> f === :hello
=> [:hello, :hello]
irb(main):013:0> Object.new === Object.new
=> false
irb(main):014:0> f === f
=> [:hello, #]
我有一个Rails 3.2应用程序,我正在Heroku Cedar堆栈上部署.这意味着应用程序本身负责提供其静态资产.我希望这些资产被gzip压缩,所以我插入Rack::Deflater到我的中间件堆栈中production.rb:
middleware.insert_after('Rack::Cache', Rack::Deflater)
Run Code Online (Sandbox Code Playgroud)
...并且curl告诉我这个广告的作用.
但是,由于Heroku将全力以赴地运行rake assets:precompile,生成一堆预先压缩的资产,我非常喜欢使用它们(而不是让Rack::Deflater所有的工作再次完成).我已经看到了使用nginx(没有在Heroku上使用)和CDN(不想使用CDN)的配方,但我还没有看到任何可以单独运行的东西.我已经将一个机架中间件一起攻击,但是我想知道这是否是最好的方法呢?
ruby ×3
activerecord ×1
authlogic ×1
cherry-pick ×1
cookies ×1
flask ×1
frameworks ×1
git ×1
gzip ×1
heroku ×1
javascript ×1
kindle-fire ×1
nginx ×1
passenger ×1
postgresql ×1
proc-object ×1
python ×1
rack ×1
rebase ×1
rspec ×1
rspec-rails ×1
ruby-1.9 ×1
session ×1
wsgi ×1