decorate_collection
用在 集合
上,decorate
用在实例上。
盲猜:
# 以下等价
ArticleDecorator.decorate_collection(Article.all)
Article.all.each(&:decorate)
# 以下等价
Article.first.decorate
ArticleDecorator.decorate_collection([Article.first])
如有这个能力为什么去贵公司?贵公司有什么过人之处?
I agree with you.
It is really a little too expensive. I read almost all his blogs. Although I've always wanted to buy this book on impulse, my pocket always pulls me back to reality.
不懂就问,你心目中的面试是怎么面试?
2.6.5 (main):0 > Podcast.frequencies
=> {"unknown"=>0, "daily"=>1, "weekly"=>7, "biweekly"=>14, "monthly"=>31, "periodic"=>366}
2.6.5 (main):0 > Podcast.where(frequency: ["daily", "weekly"]).count
(14.0ms) SELECT COUNT(*) FROM "podcasts" WHERE "podcasts"."frequency" IN ($1, $2) [["frequency", 1], ["frequency", 7]]
=> 4317
2.6.5 (main):0 > Podcast.ransack(frequency_in: ["daily", "weekly"]).result.count
(11.6ms) SELECT COUNT(*) FROM "podcasts" WHERE "podcasts"."frequency" IN (0, 0)
=> 166
2.6.5 (main):0 > Podcast.ransack(frequency_in: [1, 7]).result.count
(14.9ms) SELECT COUNT(*) FROM "podcasts" WHERE "podcasts"."frequency" IN (1, 7)
=> 4317
打破零回复。
很多前端包,比如 select2
可以直接打包 yarn add select2
引入了。
啊 啊啊 今天上午是你?
刚入职场的年轻工程师如何判断他/她所要投资的技术是像 2006 年左右的 Rails、2007 年左右的 Hadoop、还是更像 2010 年前后的 MongoDB?有点像投资创业公司,如何押对宝?还是尽量选择无聊的成熟的老技术、专注于解决实际问题、白猫黑猫抓到老鼠就是好猫?
但是呢,新人毕竟是新人,一头雾水,就想经常逃课的人,要考试了一样,不先看重点,而是去钻研难题,死翘翘了
这么酷炫的技巧...
def before_action(method_name, options)
action_module = Module.new do
send :define_method, options[:for] do |*args, &block|
send method_name
super(*args, &block)
end
end
prepend action_module
end
恍然大悟,突然想起来之前遇到的一个 bug...
最后一个插件就是针对 VIM 的
1. action_name == "create"
2. params[:action] == "create"
3. request.post?
你这个帖子,为什么没有被和谐掉!
===
等价于 case when 中的条件判断:
condition = 'hello'
case condition
when String
when User
When (1...10)
when /ello/
end
更侧重归属感。
啊哈,以为有什么暗黑高科技
我是在 ActiveSupport 扩展里面看到的,想请教一下,你是怎么定位源码的位置的?
# use helper
2.3.3 (main):0 > helper.number_to_currency 7777777
=> "¥ 7,777,777.00"
# active_support
2.3.3 (main):0 > 7777777.to_s(:currency)
=> "¥ 7,777,777.00"
# include precision
2.3.3 (main):0 > 7777777.to_s(:currency, precision: 3)
=> "¥ 7,777,777.000"
这帖子还吵起来了
class A
define_singleton_method :loudly do |message|
puts message.upcase
end
end
A.loudly "my message"
哈哈哈哈哈嗝
AA 是想插入的值/?
整理的简直了... 赞
gen install bundler
bundle install
问题如下:
» c [ruby-2.4.0][10:00:54]
/Users/dubing/.rvm/rubies/ruby-2.4.0/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- bundler/setup (LoadError)
from /Users/dubing/.rvm/rubies/ruby-2.4.0/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/dubing/workspace/vcooline/code_event_back_service/config/boot.rb:3:in `<top (required)>'
from bin/rails:3:in `require_relative'
from bin/rails:3:in `<main>'
重新安装bundler: gem install bundler
Fetching: bundler-1.16.2.gem (100%)
Successfully installed bundler-1.16.2
1 gem installed
然后bundle install
然后世界顺畅了。
» c [ruby-2.4.0][10:04:32]
Loading development environment (Rails 5.0.2)
gem install awesome_print # <-- highly recommended
2.4.0 (main):0 >
自己 200 块提心吊胆,别人投了 200W, 旅游北西东南...
学习到了,你好认真,灰常谢谢你提供的详细的解释。学习了。
我在处理的时候是这样写的
class User < ApplicationRecord
avatar
super || 'default value'
end
end
你的写法,比我的优雅了太多了。相形见绌。
No effect
你这里只是使用了 attr_accessor
, 接着...
这个是为了,有些人没有上传头像,才会调用默认头像, 可是你这种就会,一直使用默认头像,毕竟 real_avatar
始终是空。
user model:
class User < ApplicationRecord
def avatar
real_avatar.present? ? "real_avatar" : "default.png"
end
alias :real_avatar :avatar
end
执行结果:
2.4.2 (main):0 > user = User.last
User Load (0.6ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT $1 [["LIMIT", 1]]
=> #<User:0x00007fd3cc9330a8
id: 2,
uid: "017526292153702",
avatar: "http://img2.imgtn.bdimg.com/it/u=3563567972,3348399262&fm=27&gp=0.jpg",
nickname: "Nick-member",
created_at: Fri, 19 Jan 2018 00:26:16 CST +08:00,
updated_at: Fri, 19 Jan 2018 00:26:16 CST +08:00>
2.4.2 (main):0 > user.avatar
SystemStackError: stack level too deep
from /Users/dubing/workspace/vcooline/group_buying_front/app/models/user.rb:18:in `avatar'
2.4.2 (main):0 >