我想干掉以下代码。我知道我可以将if和else语句组合成一行但是有更好的方法吗?谢谢,
def group_access
@group = Group.find_by_url(params[:id])
if user_signed_in?
if @group.is_private == true and current_user.id == @group.user_id
return
end
if @group.is_private == true and current_user.id != @group.user_id
render "show_noaccess"
end
end
if !user_signed_in?
if @group.is_private == false
return
end
if @group.is_private == true
render "show_noaccess"
end
end
end
答案 0 :(得分:1)
def group_access @group = Group.find_by_url(params[:id])
if @group.is_private? and current_user.try(:id) != @group.user_id
render "show_noaccess"
end
end