p (Math.asin(Math.cos("a".to_i)).to_i<<(Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i))-(Math.asin(Math.cos("a".to_i)).to_i<<(Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i))-(Math.asin(Math.cos("a".to_i)).to_i<<Math.asin(Math.cos("a".to_i)).to_i)
或者写正常一点……
z = Math.asin(Math.cos("a".to_i)).to_i
p (z<<(z+z+z+z+z+z+z+z+z+z+z))-(z<<(z+z+z+z+z))-(z<<z)
说好的图呢!
呃,求知嘛,挖一下不算错吧……
呃,Prawn 似乎只能做到这样了……
#2 楼 @quakewang
这个办法貌似不适用于有 null 的……
我想把 null 排最前,其余的倒序,
找了很久也没找到方法……
啊,终于找到了,备忘一下……
select
products.*
from
products inner join priorities
on products.category = priorities.category
order by
priorities.priority is null, -- this to put null values at the end, or use 'is not null' to put null at first
priorities.priority,
products.id -- or some other field
或者在 rails 里
.where(true).order("personal_messages.read_at is not null").order("personal_messages.id DESC")
#未读消息(阅读时间为null)在最前,其余以id倒序
折腾了半天(关键是Iconv.conv
和"str".encode("UTF-16")
这两个东东),但还是不能被 Excel 直接打开。算了,导入就导入吧……能不乱码就好=_=
#4 楼 @zj0713001 我早上还想过这个,后来查到这个帖子: http://ruby-china.org/topics/1225 于是还是想先试试 csv,哦,按那个英文作者的说法是 tsv……
#3 楼 @LarryLv 对的,我也查到了用\t的办法,试了试,确实可以。不过也不是直接双击打开,而是要先打开 Excel,然后“数据→自文件”,才会出现那个导入向导。
def self.to_csv
csv_string = CSV.generate(:col_sep => "\t", :row_sep => "\r\n") do |csv|
csv << ['姓名', 'en_name', 'email']
all.each do |r|
csv << [r.name, r.en_name, r.email]
end
end
fh = File.new("#{Rails.root}/public/abc_col_sep.csv", "wb") #创建一个可写文件流
fh.puts NKF.nkf("-wL",csv_string) #写入数据
fh.close
end
#1 楼 @zj0713001 您是指用 spreadsheet 之类的 gem 吗?
prawn 不就是后台生成 PDF 的吗……动态的 HTML 页面的意义就是动态的数据对吗?
我开始也和 LZ 一样,不过现在貌似搞定了。
思路是这样的:我自己写的 my_project.css.erb 里的路径它是可以找到的,但 extjs 的它没找到,于是我先把 extjs-all.css 改名成 extjs-all.css.erb,很不幸,还是不行。
然后我发现我自己的 css 里用到了这样的方法:
background-image: url('<%= asset_path("silk_icon/add.png") %>') !important;
于是我把那个长长的 css 格式化了,然后把图片路径也换成这样的格式,但还是没找到。
再然后,我在http://ihower.tw/rails3/assets-and-ajax.html这里看到了这句话:
你可以在 terminal 中輸入 Rails.application.config.assets.paths 來查看所有的 assets 路徑
于是试了一下,Rails 果然只识别到了这一层:
"my_project/vendor/assets/javascripts", "my_project/vendor/assets/stylesheets"
于是就很简单了,查找替换嘛。所有的图片链接全部改成这样:
.x-box-tl {
background-image: url('<%= asset_path("extjs4/resources/themes/images/default/box/corners.gif") %>')
}
测试,OK……
之前的问题倒是解决了,现在又有新问题,就搭车问了吧…… 之前大部分是在公司内部用,我用的开发模式,速度还可以。 现在出差在外的同事发现速度很慢无法接受,我想了一下,似乎是开发模式下不会缓存 extjs-all.js 那个大 JS,于是想弄成产品模式。 但产品模式下有一个问题是:我自己写的 CSS 里的图片能被 precompile 并正常显示,但 extjs 自带的图片都无法显示
Started GET "/" for 127.0.0.1 at 2013-09-10 14:37:28 +0800
Processing by IndexController#index as HTML
Rendered index/index.html.erb within layouts/application (2.0ms)
Compiled extjs4/resources/css/ext-all.css (0ms) (pid 11943)
Compiled application.css (5ms) (pid 11943)
Compiled EIM.css (82ms) (pid 11943)
Compiled ux/BoxSelect.css (0ms) (pid 11943)
Compiled extjs4/ext-all-debug.js (77ms) (pid 11943)
Compiled extjs4/ext-lang-zh_CN.js (0ms) (pid 11943)
Compiled app.js (0ms) (pid 11943)
Compiled application.js (184ms) (pid 11943)
Compiled patch.js (0ms) (pid 11943)
Completed 200 OK in 13439ms (Views: 13438.7ms | ActiveRecord: 0.0ms)
然后但凡遇到 extjs 自己的图片文件的地方,后台就报一个这个错:
Started GET "/resources/themes/images/default/grid/page-last.gif" for 127.0.0.1 at 2013-09-10 15:03:47 +0800
ActionController::RoutingError (No route matches [GET] "/resources/themes/images/default/grid/page-last.gif"):
actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.8) lib/rails/rack/logger.rb:26:in `call_app'
我的 extjs 是放在这个文件夹下的:
感觉上好像是它编译了 css 文件,但 css 文件里使用的指向图片的路径没有编译正确?
我说“上班无聊时听什么?”他说“我只负责帮你筛选音乐,不管你无聊哦”。怒了=_=
提交的时候手动写一下……combo 提交出来是这样的。 我反正是尽量少用能 multiselect 的 combo,实在要用的地方手写
呃,刚问完就自己找到了……
http://stackoverflow.com/questions/8371574/is-there-a-way-to-list-all-belongs-to-associations
class Thing < ActiveRecord::Base
belongs_to :foo
belongs_to :bar
end
# this would return a hash of all `belongs_to` reflections, in this case:
# { :foo => (the Foo Reflection), :bar => (the Bar Reflection) }
reflections = Thing.reflections.select do |association_name, reflection|
reflection.macro == :belongs_to
end
不删可以吗,权当备忘了……
我怎么觉得raw
就可以了呢……
还能发邮件……