我猜测rails将所有解析后的翻译yml文件存储在一种数组/哈希中.有没有办法访问这个?
例如,如果我有一个文件:
en:
test_string: "testing this"
warning: "This is just an example
Run Code Online (Sandbox Code Playgroud)
我可以做一些像I18n.translations_store [:en] [:test_string]的事吗?我可以使用YAML :: load解析yml文件,但在我的情况下,我已经将子文件夹中的yml文件拆分为组织,我很确定rails已经解析了它们.
以下是错误消息的完整输出:
Fetching: eventmachine-1.0.3.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing eventmachine:
ERROR: Failed to build gem native extension.
/Users/Tyler/.rvm/rubies/ruby-2.2.0/bin/ruby -r ./siteconf20141229-47086-wfdm3m.rb extconf.rb
checking for rb_trap_immediate in ruby.h,rubysig.h... no
checking for rb_thread_blocking_region()... no
checking for inotify_init() in sys/inotify.h... no
checking for __NR_inotify_init in sys/syscall.h... no
checking for writev() in sys/uio.h... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enable_interrupt()... no
checking for rb_time_new()... yes
checking for sys/event.h... yes
checking for sys/queue.h... yes
creating Makefile
make "DESTDIR=" clean …Run Code Online (Sandbox Code Playgroud) 我正在尝试安装基金会,但它一直让我与Jquery发生冲突
? bower install foundation
bower foundation#x cached https://github.com/zurb/bower-foundation.git#5.5.1
bower foundation#x validate 5.5.1 against https://github.com/zurb/bower-foundation.git#x
bower foundation#* cached https://github.com/zurb/bower-foundation.git#5.5.1
bower foundation#* validate 5.5.1 against https://github.com/zurb/bower-foundation.git#*
bower jquery#>= 2.1.0 cached https://github.com/jquery/jquery.git#2.1.3
bower jquery#>= 2.1.0 validate 2.1.3 against https://github.com/jquery/jquery.git#>= 2.1.0
bower modernizr#>= 2.7.2 cached https://github.com/Modernizr/Modernizr.git#2.8.3
bower modernizr#>= 2.7.2 validate 2.8.3 against https://github.com/Modernizr/Modernizr.git#>= 2.7.2
bower jquery.cookie#~1.4.0 cached https://github.com/carhartl/jquery-cookie.git#1.4.1
bower jquery.cookie#~1.4.0 validate 1.4.1 against https://github.com/carhartl/jquery-cookie.git#~1.4.0
bower fastclick#>=0.6.11 cached https://github.com/ftlabs/fastclick.git#1.0.6
bower fastclick#>=0.6.11 validate 1.0.6 against https://github.com/ftlabs/fastclick.git#>=0.6.11
bower jquery-placeholder#~2.0.7 cached https://github.com/mathiasbynens/jquery-placeholder.git#2.0.9
bower jquery-placeholder#~2.0.7 validate 2.0.9 against …Run Code Online (Sandbox Code Playgroud) 有没有办法以百分比形式打印小数,所以只有两个数字后?
我的小数将始终在1和0之间,所以我想它可以number.round(2)用第三个字符开始调用,但我无法在任何地方找到它的语法.
为了澄清,我希望将数字存储为完整小数,但以百分比形式打印.
t '.submit_button'在Rails视图中使用较短的i18n键(例如)使它们更容易键入,但它实际上是好的吗?稍后您决定重构您的视图和部分内容时,您必须记住更新相应的本地化条目.根据他们的商业含义来命名它们并且总是指定完整的密钥名称会不会更加健壮?
如果我触发pry或者byebug,最终在使用实时调试模式时光标将消失,输入将变为慢/迟.最终我必须Ctrl-C杀死独角兽/美洲狮过程.在我退出终端后,终端工作,但光标有时仍然缺失/不可见.然后我必须关闭终端并打开另一个终端.我尝试了两种不同的服务器(puma/unicorn)和两种不同的调试工具(pry和byebug).
很难说这是否与调试工具,rails服务器或我的终端有关.我正在使用具有Solarized主题的Terminal.app.
在Ruby中处理前导零的正确方法是什么?
0112.to_s
=> "74"
0112.to_i
=> 74
Run Code Online (Sandbox Code Playgroud)
为什么要转换0112成74?
如何转换0112为字符串"0112"?
我想定义一个方法,该方法将整数作为参数,并以其降序返回数字.
但是当我有前导零时,这对我来说似乎不起作用:
def descending_order(n)
n.to_s.reverse.to_i
end
Run Code Online (Sandbox Code Playgroud) 我正在尝试将多个文件发送到浏览器.我不能像下面的代码中那样为每条记录调用send_data,因为我得到了双重渲染错误.根据这篇文章,我需要创建文件并压缩它们,以便我可以在一个请求中发送它们.
@records.each do |r|
ActiveRecord::Base.include_root_in_json = true
@json = r.to_json
a = ActiveSupport::MessageEncryptor.new(Rails.application.config.secret_token)
@json_encrypted = a.encrypt_and_sign(@json)
send_data @json_encrypted, :filename => "#{r.name}.json" }
end
Run Code Online (Sandbox Code Playgroud)
我创建与哈希数组@json_encrypted和file_name每个记录.我的问题是如何为每条记录创建一个文件,然后将它们捆绑成一个zip文件,然后将该zip文件传递给send_file.或者更好的是,屏幕上会弹出多个文件下载对话框.每个文件一个.
file_data = []
@records.each do |r|
ActiveRecord::Base.include_root_in_json = true
@json = r.to_json
a = ActiveSupport::MessageEncryptor.new(Rails.application.config.secret_token)
@json_encrypted = a.encrypt_and_sign(@json)
file_data << { json_encrypted: @json_encrypted, filename: "#{r.name}.json" }
end
Run Code Online (Sandbox Code Playgroud) rails 4 中是否有等效的update_columnsforhstore属性?
我的模型是:
class Image < ActiveRecord::Base
store_accessor :additions, :small, :medium, :big, :image_version
end
Run Code Online (Sandbox Code Playgroud)
假设我想更新small.
我试过:
@image = Image.first
@image.update_columns(small: 'my_small_image')
Run Code Online (Sandbox Code Playgroud)
但我当然收到:
PG::UndefinedColumn: ERROR: column "small" of relation "contents" does not exist
LINE 1: UPDATE "images" SET "small" = 'my_small_image' WHERE "imag...
^
: UPDATE "images" SET "small" = 'my_small_image' WHERE "images"."id" = 1
Run Code Online (Sandbox Code Playgroud)
有没有简单的方法来做到这一点?
编辑:我不能使用update_attributes,因为我只需要保存传递的参数。
update_attributes调用save,我不想要这个,因为它保存了所有其他更改的属性,而不仅仅是通过的属性。
例子:
@image = Image.first
@image.big = 'fjdiosjfoa'
@image.update_attributes(small: 'my_small_image') …Run Code Online (Sandbox Code Playgroud) ruby ×5
rails-i18n ×2
actionmailer ×1
bash ×1
bower ×1
decimal ×1
eventmachine ×1
gcc ×1
hstore ×1
integer ×1
javascript ×1
jquery ×1
json ×1
octal ×1
osx-yosemite ×1
percentage ×1
postgresql ×1
pry ×1
string ×1
yaml ×1
zip ×1