大女儿很漂亮,小女儿毛茸茸的很萌 恭喜呀
首先,仅仅作为一个建议,日后发帖若含代码希望能格式化好 (具体方法可按“M”键查看更多 帮助。)
然后再说一下报错原因:基本上报错信息里已经写得比较明白了,是对nil
调用了gsub
, 回到代码里会知道应该是 explore 那一行没找到内容。至于为何找不到上个回复已经说得很明白了
最后简单帮你修正下,把 explore 那行用下面这个替换下试试
explore xpath: '//*[@class="wrapper"]/div[1]/div[1]/div[2]/ul/li[1]/a' do |e|
貌似 github 主页结构已经和些那个 readme 时候有出入了
页面上已经没有id=wrapper
的 div 之后class="wrapper"
的 div
bundle exec rake db:migrate RAILS_ENV=development 其实仔细看看错误信息会很有帮助
不过个这依附于 Sublime Text 2/3
我也补一个吧 Sublimerge 用来进行文件比较的,免费版同样有全功能,只不过每用 2 次就询问你是否要购买
May the force be with you...
case/when那里如果不好理解, 可以拿<=>
方法做个类比
比如我们自己定义了个User
类,如果直接就User.all.sort
, 是不可以的,
如果想这么用,你就需要首先在 User 里面定义一个 <=>
方法用于比较 2 个 user 对象
稍微有点不同的是,因为===
是定义在 Object 里的,所以即便对自己定义的类里面不重写===
方法,一样可以对其使用 case/when. 但是这样会调用Object#===
, 可能不会得到自定义类需要达到的效果。
依然用我顶楼===
里的那个例子来说
如果 Integer 里面没有重写===
方法,那么得到的返回值就不再是"case Integer",而是"case 5"了
#1 楼 @palytoxin
===
作用是不太好说明白,一开始是想说成“a 定义了一个范围然后判断 b 是否在这个范围之内”,但是这么很容易就让人联想到了include?
进一步说, Integer === 5
可以返回 true,因为 5 在 Integer 的范围(抽屉)里,但是5 === Integer
显然是不行的
至于作用,最主要的就是上面说的,在自己的类里面重写===
,让 case/when 条件表达式根据自己的类的业务,有个判断 case 后面的值该进入哪个分支的依据
比如这里, Regexp 重写了===
方法,于是 when 后面可以放正则表达式
不知楼主是否遇到的是N+1 Query的情况
Dance.includes(:user).where(some conditions)
可以把之前项目的 ability.rb 文件给你参考下
#coding: utf-8
class Ability
include CanCan::Ability
def initialize(user, mall=nil, product=nil)
user ||= User.new # guest user (not logged in)
if user.has_role? :admin
can :manage, :all
else
############ All ##############
can [:read], User do |do_user|
user.has_role?(:admin, mall) && do_user.has_role?(:user, mall)
end
can [:read, :update], User do |do_user|
do_user.id == user.id || ( do_user.mall_id == mall.id && user.has_role?(:admin, mall) )
end
can [:add_admin], User do |do_user|
user.id == mall.owner_id && do_user.mall_id == mall.id
end
can [:remove_admin], User do |do_user|
user.id == mall.owner_id && do_user.mall_id == mall.id
end
############ aidou_users ##############
can [:create], Org do |org|
user.has_role?(:org_user)
end
can [:read,:update], Org do |org|
user.has_role?(:admin, org)
end
can [:index], Mall do |mall|
user.has_role?(:admin, mall.org)
end
can [:show], Mall
can [:create], Mall do |mall|
user.has_role?(:org_user)
end
can [:update], Mall do |mall|
user.has_role?(:admin, mall)
end
############ mall_admins && mall_users ##############
can [:read], Teacher do |teacher|
mall.can_serve?(false, "Teacher", :read)
end
can [:create, :created], Teacher do |teacher|
user.has_role?(:admin, mall) && mall.can_serve?(false, "Teacher", :create)
end
can [:update, :destroy], Teacher do |teacher|
(user.has_role?(:admin, mall) || ( user.has_role?(:mall_teacher, mall) && teacher.user_id == user.id)) && mall.can_serve?(false, "Teacher", :update)
end
#-------------------------------------------------------
can [:read], Product do |product|
mall.can_serve?(false, "Product", :read)
end
can [:grouped], Product do |product|
mall.can_serve?(false, "Product", :read) && product.accepts_user?(user)
end
can [:create, :update, :destroy, :enable, :disable, :update_grouping, :edit_grouping], Product do |product|
user.has_role?(:admin, mall) && mall.can_serve?(false, "Product", :create)
end
#-------------------------------------------------------
can [:index], Episode do |episode|
user.has_role?(:admin, mall) && mall.can_serve?(false, "Episode", :read)
end
can [:show], Episode do |episode|
(user.has_role?(:admin, mall) || user.can_read_item?(episode, product)) && mall.can_serve?(true, "Episode", :show)
end
can [:create, :update], Episode do |episode|
user.has_role?(:admin, mall) && mall.can_serve?(true, "Episode", :create, true)
end
can [:destroy], Episode do |episode|
user.has_role?(:admin, mall) && mall.can_serve?(false, "Episode", :destroy)
end
can [:index], Live do |live|
user.has_role?(:admin, mall) && mall.can_serve?(false, "Live", :read)
end
can [:show], Live do |live|
(user.has_role?(:admin, mall) || user.can_read_item?(live, product)) && mall.can_serve?(true, "Live", :show)
end
can [:create, :update], Live do |live|
user.has_role?(:admin, mall) && mall.can_serve?(true, "Live", :create)
end
can [:destroy], Live do |live|
user.has_role?(:admin, mall) && mall.can_serve?(false, "Live", :destroy)
end
can [:index], FaceToFace do |f2f|
user.has_role?(:admin, mall) && mall.can_serve?(false, "Episode", :read)
end
can [:show], FaceToFace do |f2f|
user.has_role?(:admin, mall) && mall.can_serve?(true, "Episode", :show)
end
can [:create, :update, :destroy], FaceToFace do |f2f|
user.has_role?(:admin, mall) && mall.can_serve?(true, "Episode", :update)
end
#-------------------------------------------------------
can [:read], Order do |order|
((user.has_role?(:admin, mall) && order.mall_id == mall.id) || (order.user_id == user.id)) && mall.can_serve?(false, "Order", :read)
end
can [:check], Order do |order|
user.has_role?(:admin, mall) && can_serve?(false, "Order", :read)
end
can [:waiting, :checkout, :paid], Order do |order|
order.user_id == user.id && mall.can_serve?(false, "Order", :checkout)
end
can [:create], Order do |order|
user.id != nil && mall.can_serve?(false, "Order", :create)
end
can [:update, :destroy, :clear_waiting], Order do |order|
(order.user_id == user.id) && order.status == Order::STATUS["未付款"] && mall.can_serve?(false, "Order", :destroy)
end
#-------------------------------------------------------
can [:read], Transaction do |t|
(user.has_role?(:admin, mall) && t.mall_id == mall.id) || (t.user_id == user.id)
end
can [:update, :destroy], Transaction do |t|
(t.user_id == user.id) && t.status == Order::STATUS["未付款"]
end
#-------------------------------------------------------
can [:create], Paper do |paper|
user.has_role?(:admin, mall) && mall.can_serve?(false, "Paper", :create)
end
can [:manage], Paper do |paper|
user.has_role?(:admin, mall) && paper.mall_id == mall.id && mall.can_serve?(false, "Paper", :manage)
end
can [:read], Paper do |paper|
user.has_role?(:user, paper.mall) && mall.can_serve?(false, "Paper", :read)
end
#-------------------------------------------------------
can [:create], Question do |question|
user.has_role?(:admin, mall) && mall.can_serve?(false, "Question", :create)
end
can [:manage], Question do |question|
user.has_role?(:admin, mall) && question.mall_id == mall.id && mall.can_serve?(false, "Question", :manage)
end
#-------------------------------------------------------
can [:create], Answer do |answer|
( user.has_role?(:admin, mall) || user.has_role?(:user, mall) ) && mall.can_serve?(false, "Answer", :create)
end
can [:read, :incorrect_answers], Answer do |answer|
answer.user_id == user.id && mall.can_serve?(false, "Answer", :read)
end
#-------------------------------------------------------
can [:read], WatchingRecord do |rec|
user.has_role?(:admin, rec.mall) || user.id == rec.user_id
end
#-------------------------------------------------------
can [:create], Category do |cat|
user.has_role?(:admin, mall)
end
can [:manage], Category do |cat|
user.has_role?(:admin, mall) && cat.mall_id == mall.id
end
can [:read] ,Category do |cat|
user.has_role?(:admin, mall)
end
#-------------------------------------------------------
can [:manage, :close], Comment do |comment|
user.has_role?(:admin, mall) && mall.can_serve?(false, "Comment", :manage)
end
can [:create], Comment do |comment|
product.accepts_user?(user, comment.commentable) && mall.can_serve?(false, "Comment", :create)
end
can [:manage], Like do |l|
user.has_role?(:admin, mall) && mall.can_serve?(false, "Comment", :manage)
end
can [:create], Like do |l|
mall.can_serve?(false, "Comment", :create)
end
#-------------------------------------------------------
can [:index], Payment do |p|
user.has_role?(:admin, mall) || (user.has_role?(:mall_teacher, mall) && p.user_id == user.id)
end
#-------------------------------------------------------
can [:read], Face do |face|
(user.has_role?(:admin, mall) || user.id = face.user_id) && mall.can_serve?(false, "Face", :read)
end
can [:create], Face do |face|
(user.has_role?(:admin, mall) || user.has_role?(:user, mall)) && mall.can_serve?(false, "Face", :create)
end
can [:destroy], Face do |face|
(user.has_role?(:admin, mall) || user.id = face.user_id) && mall.can_serve?(false, "Face", :destroy)
end
#-------------------------------------------------------
can [:manage], Group do |group|
user.has_role?(:admin, mall) && mall.can_serve?(false, "Mall", :show)
end
#-------------------------------------------------------
can [:create], UserQuestion do |quest|
if product
user.can_read_item?(quest.questionable, product) && mall.can_serve?(false, "Problem", :create)
else
mall.can_serve?(false, "Problem", :create)
end
end
can [:index, :update, :destroy], UserQuestion do |quest|
(user.has_role?(:admin, mall) || user.id == quest.user_id) && mall.can_serve?(false, "Problem", :create)
end
can [:create], UserAnswer do |answer|
mall.can_serve?(false, "Problem", :create)
end
can [:index, :update, :destroy], UserAnswer do |answer|
(user.has_role?(:admin, mall) || user.id == answer.user_id) && mall.can_serve?(false, "Problem", :create)
end
end
end
end
AWS 对新注册的用户有一年期的免费套餐,不过速度一般,配置的话跑个练手的程序足够。 AWS 免费使用套餐
公司带宽有限早上看到提示升级直接忽略了 , 晚上回家折腾自己本子去
呃...多谢
昨晚下班前 AWS 来封邮件要求升级 openssl, 当时没太在意. 晚上回去看了下新闻,好像这次闹得挺凶
哈哈,高哥也来这里招战将了,帮顶下。
发帖人是我入门 rails 的引路人与导师,技术很棒,人也非常好,富有热情而且幽默感十足。与他共事你要时刻做好被委以重任的准备,每天都会充满挑战,另一方面你却不需要过于担心 overtime,合理的时间安排与高效率的工作比没完没了的加班更受推崇。
依然很怀念曾经那些整个公司为共同的理念努力拼搏的日子,好可惜我孩子年前刚过百天,过不去北京,只能在这里精神上支持和向往了。
大家多多投简历吧,见到他本人和他聊两句会比我在这码字更有说服力。
本子太老硬盘小,时不时硬盘空间吃紧,终于决定把rvm干掉换rbenv了,吃掉了将近5G的空间,顺便把mongodb的 journal 也干掉,瞬间觉得硬盘又复活过来...
生命如此美妙,我却如此胡造,这样不好,不好...
class Product < ActiveRecord::Base
COMMENT_NAMES = {1 => ['良好','F'], 2 => ['非常好','G'], 3 => ['理想','VG'], 4=> ['完美','EX']}
def comment_name
COMMENT_NAMES[self.comment].first
end
def comment_short_name
COMMENT_NAMES[self.comment].last
end
end