作为一个例子,我有一个默认的英语语言环境文件"en.yml"与内容:
en:
messages: messages
users: users
Run Code Online (Sandbox Code Playgroud)
现在,有一个客户希望在他的产品中将消息命名为讨论,但用户应该保留用户.所以我想要做的是创建"customer.en.yml"文件
en:
messages: discussions
Run Code Online (Sandbox Code Playgroud)
这将覆盖默认的"消息"翻译,但会保持所有其他单词相同.我怎么能实现它?
因为如果我加载en.yml:
config.i18n.load_path += Dir[File.join(RAILS_ROOT, 'config', 'locales', '*.{rb,yml}')]
Run Code Online (Sandbox Code Playgroud)
然后加载customer.en.yml(APP_CONFIG ['customer_name']在之前定义)with
config.i18n.load_path += Dir[File.join(RAILS_ROOT, 'config', 'custom_locales', APP_CONFIG['customer_name']+'.{rb|yml}')]
Run Code Online (Sandbox Code Playgroud)
它只会覆盖我的"en"语言环境,"用户"翻译会消失,对吗?
我试图使用ffmpeg将udp流转换为帧.我运行以下命令:
ffmpeg -loglevel debug -strict 2 -re -i "udp://192.168.15.50:3200?fifo_size=1000000&overrun_nonfatal=1" -r 8 -vf scale=432:243 -f image2pipe -vcodec ppm pipe:1
Run Code Online (Sandbox Code Playgroud)
它发生在不同的流类型,mpeg2video和h264.核心处理此特定流的CPU负载低于30%,其低质量sd流的分辨率为640x576.
它适用于大多数时间,但有时,偶尔会发生延迟,帧会在稍后到达.所以我想要8 fps,但有时我会更少,有时甚至更多.
为什么会出现这种延迟?如何减少延迟?
更新:我尝试将其更改为:
ffmpeg -loglevel debug -i "udp://192.168.15.50:3200?fifo_size=1000000&overrun_nonfatal=1" -r 8 -preset ultrafast -fflags nobuffer -vf scale=432:243 -f image2pipe -vcodec ppm pipe:1
Run Code Online (Sandbox Code Playgroud)
但我仍然遇到了这个问题.例如,在ffmpeg日志中我得到:
[2016/02/11 13:32:30] frame= 7477 fps=8.0 q=-0.0 size= 2299638kB time=00:15:34.62 bitrate=20156.4kbits/s dup=7 drop=15867 ^M*** dropping frame 7477 from stream 0 at ts 7475
[2016/02/11 13:32:30] ***dropping frame 7477 from stream 0 at ts 7476
[2016/02/11 13:32:30] ***dropping frame 7478 …Run Code Online (Sandbox Code Playgroud) 我试图覆盖设计注册控制器,以便用户能够上传他的化身以及更改其他数据,并在上传后裁剪userpic.
我添加了所有necesarry用户回形针属性,创建了裁剪视图,我的注册控制器看起来像这样:
class RegistrationsController < Devise::RegistrationsController
def update
if params[resource_name][:avatar].blank?
super
else
@user=resource
respond_to do |format|
if resource.update_attributes(params[resource_name])
flash[:notice]='Avatar successfully uploaded.'
format.html {
render :action => 'crop'
}
format.xml { head :ok }
else
format.html { render :action => "editpicture" }
format.xml { render :xml => @demotivator.errors, :status => :unprocessable_entity }
end
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
但是当我提交带有图片的表单时,没有任何反应,除了firefox显示"正在加载......"!在开发日志中绝对没有更新.. :(
谁能告诉我,我能做错什么?
PS.用户编辑表单看起来像这样:
<%= form_for(@user, :url => registration_path(@user), :html => {:id => "userpic_form", :method => :put, :multipart => true}) do |f| %>
<p …Run Code Online (Sandbox Code Playgroud) 在我的网站上,我允许用户使用他们在图片上指定的文字行创建图片
目前我用于imagemagick转换 - 我指定svg模板,让转换做其余的
这是代码的一部分,负责输出图片中的文本
<text text-anchor="middle" x="50%%" y="%s"
font-family="Times New Roman" font-size="55"
style="fill:rgb(255,255,255);">
%s
</text>
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果用户提供非常长的字符串,则文本不适合图像.
如果文本不适合图片,我希望文本自动调整为较小的字体.是否可以使用svg模板?如果没有,可能是其他解决方案
是否可以指定参数:连接类似于:条件的方式?
这是一个例子(sql代码无关紧要)
named_scope :threads, {
:joins => [" LEFT JOIN groups_messages gm ON messages.id=gm.message_id AND gm.group_id IN (?) ",@group_ids_array],
:conditions => ["creator_id=? AND messages.id IN (?)", current_user_id, @message_ids_array]
}
Run Code Online (Sandbox Code Playgroud)
在这个示例参数:条件将正确插入,但对于:连接我会得到一个错误
Association named ' LEFT JOIN groups_messages gm ON messages.id=gm.message_id and gm.group_id IN (?) ' was not found; perhaps you misspelled it?
Run Code Online (Sandbox Code Playgroud)
什么函数替换参数:条件?
如果我不知道对象是什么,如何从对象中获取控制器名称?
我想做:
object.class.tableize
Run Code Online (Sandbox Code Playgroud)
但是Rails说:
undefined method `tableize' for #<Class:0xb6f8ee20>
Run Code Online (Sandbox Code Playgroud)
我尝试添加相同结果的demodulize.
谢谢
在我的rails 4项目css使用字体文件.所以他们需要另外预编译.
我通过在config/environments/production.rb中添加以下行来实现这一目标
# Add the fonts path
config.assets.paths << Rails.root.join('vendor', 'assets', 'fonts','fonts')
#
# # Precompile additional assets
config.assets.precompile += %w( *.svg *.eot *.woff *.ttf )
Run Code Online (Sandbox Code Playgroud)
并运行rake资产:在生产中预编译.
但结果如下:
I, [2013-10-10T19:27:51.931963 #16052] INFO -- : Writing /var/lib/openshift/521e19c85004460a8e000107/app-root/runtime/repo/public/assets/fonts/glyphicons-halflings-regular-ab2f6984951c07fd89e6afdefabd93c7.eot
I, [2013-10-10T19:27:51.940615 #16052] INFO -- : Writing /var/lib/openshift/521e19c85004460a8e000107/app-root/runtime/repo/public/assets/fonts/glyphicons-halflings-regular-24dfb40c91db789b8b8faba6886ac1ef.svg
I, [2013-10-10T19:27:51.950685 #16052] INFO -- : Writing /var/lib/openshift/521e19c85004460a8e000107/app-root/runtime/repo/public/assets/fonts/glyphicons-halflings-regular-4b2130768da98222338d1519f9179528.ttf
I, [2013-10-10T19:27:51.983230 #16052] INFO -- : Writing /var/lib/openshift/521e19c85004460a8e000107/app-root/runtime/repo/public/assets/fonts/glyphicons-halflings-regular-7a07f26f72466361ac9671de2d33fd1c.woff
Run Code Online (Sandbox Code Playgroud)
和css文件引用没有此md5指纹的字体文件.
我怎样才能预编译资产,以便在没有md5指纹的情况下生成资产?或者我应该在这种情况下将它们放到public/fonts /文件夹中?
为什么Ruby不会strptime将其转换为DateTime对象:
DateTime.strptime('Monday 10:20:20', '%A %H:%M:%S')
# => ArgumentError: invalid date
Run Code Online (Sandbox Code Playgroud)
虽然这些工作?
DateTime.strptime('Wednesday', '%A')
# => #<DateTime: 2015-11-18T00:00:00+00:00 ((2457345j,0s,0n),+0s,2299161j)>
DateTime.strptime('10:20:20', '%H:%M:%S')
# => #<DateTime: 2015-11-18T10:20:20+00:00 ((2457345j,37220s,0n),+0s,2299161j)>
Run Code Online (Sandbox Code Playgroud) 我需要运行以下命令:
ffmpeg -i input.jpg -vf scale="'if(gt(a,4/3),320,-1)':'if(gt(a,4/3),-1,240)'" output_320x240_boxed.png
Run Code Online (Sandbox Code Playgroud)
所以我执行:
cmd = exec.Command("ffmpeg", "-i", "input.jpg", "-vf", "scale=\"'if(gt(a,4/3),640,-1)':'if(gt(a,4/3),-1,300)'\"", "output_320x240_boxed.png")
Run Code Online (Sandbox Code Playgroud)
它失败并出现以下错误:
Error when evaluating the expression 'if(gt(a,4/3),-1,300)"'.
Maybe the expression for out_w:'"if(gt(a,4/3),640,-1)' or for out_h:'if(gt(a,4/3),-1,300)"' is self-referencing.
Run Code Online (Sandbox Code Playgroud)
在命令行中执行时命令有效.为什么会发生这种情况,如何逃避这些双引号以防止出现此错误?
这段代码:
[{:id => 1,:key => 3},{:id => 2,:key => 4},{:id => 3, :key => 5}].
inject(Hash.new([])){|h,i| h[i[:key]] << i; h}
Run Code Online (Sandbox Code Playgroud)
返回:
{}
Run Code Online (Sandbox Code Playgroud)
虽然这个:
[{:id => 1,:key => 3},{:id => 2,:key => 4},{:id => 3, :key => 5}].
inject(Hash.new([])){|h,i| h[i[:key]] += [i]; h}
Run Code Online (Sandbox Code Playgroud)
返回:
{3=>[{:id=>1, :key=>3}, {:id=>3, :key=>3}], 4=>[{:id=>2, :key=>4}]}
Run Code Online (Sandbox Code Playgroud)
为什么第一个案例的工作方式不同?