Lydia's blog

Every day to be a little better


  • Home

  • Archives

  • Search

rails- 数组去除空字符串

Posted on 2018-03-08 16:18

noEmptyCities = cities.reject { |c| c.empty? }

reject 后面跟着要去除的条件

rails-手机跟网页版页面分开

Posted on 2018-03-07 17:54

controller

1
before_action :detect_browser, only: :index

在对应的action里面

1
2
3
4
5
respond_to do |format|
format.html do |variant|
variant.mobile
end
end

方法

1
2
3
def detect_browser
request.variant = :mobile if browser.device.mobile?
end

页面名称 例如:index.html+mobile.erb
这样在手机上就会自动走手机版的页面了

ps: 不用添加路由

html-tag 嵌套

Posted on 2018-02-22 14:12

如果想在a标签之中嵌套a标签 比较简单的方法是在内层的a标签外嵌套一层 object 标签
但是这种方法 IE8及以下是不支持的,chrome firefox IE9及以上均支持

IE8及以下建议:将两层a 标签都做成绝对定位将位置分开

css- 实现框内斜线

Posted on 2018-02-21 12:31

右上左下
background:
linear-gradient(135deg, transparent 49.5%, deeppink 49.5%, deeppink 50.5%, transparent 50.5%);
左上右下
background:
linear-gradient(45deg, transparent 49.5%, deeppink 49.5%, deeppink 50.5%, transparent 50.5%);

css-有字的分割线

Posted on 2018-02-07 11:05

html

1
2
3
4
5
<div class="other-example-divider">
<span class="line"></span>
<span class="text">文字</span>
<span class="line"></span>
</div>

css

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
.other-example-divider
padding-left: 30px
padding-right: 42px
height: 20px
width: 100%
display: flex
justify-content: space-between
align-items: center
.text
color: #9c9c9c
padding-left: 20px
padding-right: 20px
.line
height: 2px
flex-grow: 1
background-color: #dedfe1

rails 去掉空白符

Posted on 2018-01-31 17:41

lstrip : 去掉首空格

rstrip : 去掉尾空格

gsub : 去掉全部空格,不过要用到pattern匹配

eg:

s1 = “ Test whitespace”
s2 = “ hello Ruby Rails “
s3 = “trailing “
puts s1.lstrip+s3 # show lstrip remove leading whitespace
puts s2.rstrip+s3 # show rstrip remove trail whitespace
puts s1.strip + s2.strip + s3 # show strip remove leading and trail whitespace
puts s2.gsub(/\s+/,’’)
puts s2.gsub(‘ ‘,’’)
puts s2.gsub!(‘ ‘,’’)
puts s2.gsub(//,’’) # four methods show remove all whitespace

str.gsub(/^ | $/,””)去掉首尾空格

css-字过长不显示

Posted on 2018-01-25 17:04

overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;

ps:对于table来说要给 table 加一个

1
2
3
table {
table-layout: fixed;
}

css-cursor

Posted on 2018-01-14 14:25

361515911136_.pic_hd.jpg

禁止:cursor: not-allowed;

css-控制tooltip的width

Posted on 2018-01-10 16:13

找到会出现tooltip的外层
用这个class .tooltip-inner {
width: xxx;
}

ios- 弹出jquery的confirm

Posted on 2018-01-08 17:16
1
2
3
4
5
6
7
8
9
10
 - (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL))completionHandler{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:message?:@"" preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:([UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
completionHandler(NO);
}])];
[alertController addAction:([UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
completionHandler(YES);
}])];
[self presentViewController:alertController animated:YES completion:nil];
}

ps: 一定要加
_webView.UIDelegate = self;

1…161718…28

Lydia

This is lydia's blog

277 posts
1 categories
46 tags
© 2020 Lydia
Powered by Hexo
|
Theme — NexT.Muse v5.1.4