1)宝石里面有耙子任务的"最佳"位置吗?我见过它们/tasks,/lib/tasks我看到它们写成了- *.rb并且*.rake不确定哪个(如果有的话)是'正确的'
2)在环境中配置gem后,如何将它们提供给应用程序?
最好是红宝石,但逻辑足够好......
鉴于本周非标准,我需要一年中的周数.所以,假设您将周定义为星期六 - >星期五.然后,给定一个日期,这个周数(1-52)是什么?
strftime有%U:
> Time.now.strftime('%U')
> => "28"
Run Code Online (Sandbox Code Playgroud)
...但当然假设标准星期日 - >星期六.
对于1.9.2p0,Date#parse采用UE格式.如果你不相信我,请查看format.rb,line:1042.
无论如何,我怎样才能让它采用美国格式,以便:
> Date.parse("10/4/2010")
=> Mon, 04 Oct 2010
Run Code Online (Sandbox Code Playgroud)
而不是4月10日.
我试过这个:
class Date
def _parse_eu(str,e)
_parse_us(str,e)
end
end
Run Code Online (Sandbox Code Playgroud)
但没有运气.还有其他想法吗?
我的生产asset_host配置如下所示:
config.action_controller.asset_host = Proc.new { |source, request|
if request.ssl?
"#{request.protocol}#{request.host_with_port}"
else
"#{request.protocol}assets#{(source.length % 4) + 1}.example.com"
end
}
Run Code Online (Sandbox Code Playgroud)
......或多或少直接来自文档:
http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html
当我去资产:预编译,我得到这个:
$ RAILS_ENV=production bundle exec rake assets:precompile
rake aborted!
This asset host cannot be computed without a request in scope. Remove
the second argument to your asset_host Proc if you do not need the
request.
Run Code Online (Sandbox Code Playgroud)
....除了我不能真正删除第二个arg,因为我需要知道请求是否是ssl.也就是说,我理解在rake任务期间没有请求生成资产....
那么如何摆脱这个渔获22?
所以我有一个疯狂的想法,我想将一个范围应用于一个包含的协会.这是我想出来的,似乎工作得很好:
class Event < ActiveRecord::Base
has_many :races
has_many :bad_races, :conditions => Race.bad_medals_sql, :class_name => "Race"
end
class Race < ActiveRecord::Base
def self.bad_medals_sql
arel_table[:prizes].eq('medals').to_sql
# This returns a string
# "`races`.`prizes` = 'medals'"
end
def self.bad_medals
where(bad_medals_sql)
end
end
Event.includes(:bad_races)
Reloading...
Event Load (0.4ms) SELECT `events`.* FROM `events`
Race Load (0.5ms) SELECT `races`.* FROM `races` WHERE (`races`.event_id IN (1,2,3,4) AND (`races`.`prizes` = 'medals'))
Run Code Online (Sandbox Code Playgroud)
问题是它真的很钝.为了在Race上定义范围(在别处使用)并在Event的关联上使用它,我必须在Race上有两个方法.对于每个范围.
我确信我可以将模式包装成插件或其他一些插件,但如果可能,我宁愿使用原生AR/ARel.这样做的任何想法?
OSX/Monterey/M1/Arm/Homebrew:我一生都无法让它工作:
./configure --with-jemalloc
Run Code Online (Sandbox Code Playgroud)
它死了
checking jemalloc/jemalloc.h presence... no
configure: error: jemalloc requested but not found
Run Code Online (Sandbox Code Playgroud)
即使它就在那里:/opt/homebrew/Cellar/jemalloc/5.2.1_1/include/jemalloc/jemalloc.js。
brew --prefix jemalloc一切看起来都是jemalloc-config --includedir正确的。
我尝试过各种版本:
export RUBY_CONFIGURE_OPTS="--with-jemalloc-include=$(brew --prefix jemalloc)/include
Run Code Online (Sandbox Code Playgroud)
和/或
./configure --with-jemalloc-include=$(brew --prefix jemalloc)/include
Run Code Online (Sandbox Code Playgroud)
但没有骰子。甚至不确定这些环境变量/标志是否受到 ruby 的尊重,或者它们是否是一些 rvm/rbenv/ruby-build 的东西。
我打算直接使用 ruby 的配置而不是 rvm/build 工具进行所有测试。
我想要一些关于是否使用fork {}来"跟踪"来自rails应用程序的进程是一个好主意的想法......
从我收集的叉子{my_method; Process#setsid}确实做了它应该做的事情.
1)使用不同的PID创建另一个进程
2)不会中断调用过程(例如,它继续等待fork完成)
3)执行孩子直到完成
..这很酷,但这是个好主意吗?叉子到底在做什么?它是否在内存中创建了我的整个rails mongrel/passenger实例的重复实例?如果是这样那将是非常糟糕的.或者,它是否以某种方式在不消耗大量内存的情况下进行.
我的最终目标是取消我的后台守护程序/队列系统,支持分叉这些进程(主要是发送电子邮件) - 但如果这不能节省内存,那么它肯定是向错误方向迈出的一步
作为更大的webapp的一部分,我想构建允许用户在离线时输入数据的功能 - 然后当他们再次建立连接时将数据发送回我的网站
对我来说,失踪的那些部分
我想将它完全保留在浏览器中,所以......
HTML5是否满足某些(或所有)目标,因为它目前在webkit/ff3中实现?
如果没有,我应该开始研究哪些技术才能完成上述所有工作.
使用守护进程,如何指定我的脚本的日志进入/ log /并且其pid进入/ tmp/pids /?
我已经阅读了文档,我看到了:dir /:dir_mode,但我只能让它做一个或另一个,而不是两个 - 如果你问我,它似乎是一个非常糟糕的选项.
使用git-svn和'典型'svn repo/trunk,/ branches/...,/ tags/...如何将本地分支推送到/ branches内的新分支?
我正在升级应用程序.目前3.1.rc8.
问题是,在开发中,在每个请求中,似乎每个资产都通过rails堆栈运行.我们正在谈论,每个图像,js和css文件(并且有很多这些文件).在第一次请求之后,它们都返回304,但它仍然是如此缓慢.
每次请求后都有很多这样的事情:
Started GET "/assets/jquery-ui-1.8.16.custom.css?body=1" for 127.0.0.1 at 2011-08-30 15:36:21 -0400
Served asset /jquery-ui-1.8.16.custom.css - 304 Not Modified (0ms)
Started GET "/assets/yui.css?body=1" for 127.0.0.1 at 2011-08-30 15:36:21 -0400
Served asset /yui.css - 304 Not Modified (0ms)
Run Code Online (Sandbox Code Playgroud)
如何在开发中使资产像在3.0.x中那样提供服务?
我也使用这些标签来防止我的css/js被编译成dev中的单个文件:
= stylesheet_link_tag 'application', :debug => Rails.env.development?
= javascript_include_tag 'application', :debug => Rails.env.development?
Run Code Online (Sandbox Code Playgroud)
这是我的application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
Bundler.require(:default, :assets, Rails.env)
end
module Fooapp
class Application < Rails::Application
config.encoding = "utf-8"
config.filter_parameters += [:password, :password_confirmation]
config.assets.enabled = true
config.assets.version …Run Code Online (Sandbox Code Playgroud) 我想使用单个haml/mustache模板,如下所示:
.foo
%h2 {{title}}
Run Code Online (Sandbox Code Playgroud)
我可以提出两种方式:
1)作为部分并传递哈希:
render :partial => 'foo', :mustache => {:title => 'hello world'}
=>
<div class='foo'><h2>hello world</h2></div>
Run Code Online (Sandbox Code Playgroud)
2)作为部分没有在脚本标记内使用的哈希:
:javascript
render :partial => 'foo'
=>
<script type='text/javascript'>
<div class='foo'><h2>{{title}}</h2></div>
</script>
Run Code Online (Sandbox Code Playgroud)
我已经尝试过各种文件名组合......"_ foo.mustache.haml",但是rails不会识别该扩展名.
另外,我正在使用ryan bates的mustache_template_handler.rb:http: //railscasts.com/episodes/295-sharing-mustache-templates
ruby ×6
date ×2
activerecord ×1
arel ×1
background ×1
backgroundrb ×1
branch ×1
daemons ×1
delayed-job ×1
git ×1
git-svn ×1
haml ×1
html5 ×1
jemalloc ×1
mustache ×1
offline ×1
rake ×1
rubygems ×1
ssl ×1
time ×1