-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.json
1 lines (1 loc) · 25.3 KB
/
content.json
1
{"meta":{"title":"Dashy","subtitle":"Dashy","description":"Android Developer","author":"Dashy","url":"http://www.dashy.cn","root":"/"},"pages":[{"title":"404 Not Found","date":"2020-01-08T16:54:43.969Z","updated":"2020-01-08T16:54:43.969Z","comments":true,"path":"404.html","permalink":"http://www.dashy.cn/404.html","excerpt":"","text":"404 Not Found **很抱歉,您访问的页面不存在** 可能是输入地址有误或该地址已被删除"},{"title":"关于","date":"2020-01-08T16:54:43.973Z","updated":"2020-01-08T16:54:43.973Z","comments":true,"path":"about/index.html","permalink":"http://www.dashy.cn/about/index.html","excerpt":"","text":"欢迎光临 Dashy’s Blog你好,我叫Dashy,欢迎浏览我的博客,我是一名 Android 开发仔,目标是成为一名Android技术专家。 网站是采用 hexo 搭建的,主题是 Material X. 业余爱好: coding 健身 动漫(One Piece) 民谣"},{"title":"所有分类","date":"2020-01-08T16:54:43.975Z","updated":"2020-01-08T16:54:43.975Z","comments":true,"path":"categories/index.html","permalink":"http://www.dashy.cn/categories/index.html","excerpt":"","text":""},{"title":"","date":"2020-01-08T16:54:43.979Z","updated":"2020-01-08T16:54:43.979Z","comments":true,"path":"mylist/index.html","permalink":"http://www.dashy.cn/mylist/index.html","excerpt":"","text":""},{"title":"所有标签","date":"2020-01-08T16:54:43.982Z","updated":"2020-01-08T16:54:43.982Z","comments":true,"path":"tags/index.html","permalink":"http://www.dashy.cn/tags/index.html","excerpt":"","text":""}],"posts":[{"title":"证书文件格式互转(cer/crt/jks/bks/keystore/pem...)","slug":"证书文件格式互转","date":"2020-01-11T14:55:00.000Z","updated":"2020-01-11T14:58:11.148Z","comments":true,"path":"2020/01/11/证书文件格式互转/","link":"","permalink":"http://www.dashy.cn/2020/01/11/%E8%AF%81%E4%B9%A6%E6%96%87%E4%BB%B6%E6%A0%BC%E5%BC%8F%E4%BA%92%E8%BD%AC/","excerpt":"","text":"序号 源证书文件格式 目标证书文件格式 所需命令 1 keystore p12 keytool -importkeystore -srckeystore xxxx.keystore -srcstoretype JKS -deststoretype PKCS12 -destkeystore xxx.p12 2 p12 jks keytool -importkeystore -srckeystore xxx.p12 -srcstoretype PKCS12 -deststoretype JKS -destkeystore xxx.jks 3 pk8 pem openssl pkcs8 -inform DER -nocrypt -in xxx.pk8 -out xxx.pem 4 pem pks12 openssl pkcs12 -export -in xxx.x509.pem -inkey platform.pem -out xxx.pkcs12 5 pks12 jks keytool -importkeystore -srckeystore xxx.pkcs12 -srcstoretype pkcs12 -srcstorepass android -destkeystore xxx.jks -deststoretype jks -deststorepass android 6 jks p12 keytool -importkeystore -srckeystore xxx.jks -destkeystore xxx.p12 -srcstoretype JKS -deststoretype PKCS12 -srcstorepass android -deststorepass android -srcalias platform -destalias platform -srckeypass android -destkeypass android -noprompt 7 p12 x509.pem openssl pkcs12 -in xxx.p12 -nodes -nokeys -out xxx.x509.pem -password pass:android 8 p12 rsa.pem openssl pkcs12 -in xxx.p12 -nodes -cacerts -out xxx.rsa.pem -password pass:android 9 rsa.pem pk8 openssl pkcs8 -topk8 -outform DER -in xxx.rsa.pem -inform PEM -out xxx.pk8 -nocrypt 10 cer jks keytool -import -file xxx.cer -keystore xxx.jks 11 cer bks keytool -importcert -v -trustcacerts -alias xx -file xxx.cer -keystore xxx.bks -storetype BKS -storepass ‘123456’ 12 bks cer keytool -export -alias xx -file xxx.cer -keystore xxx.bks -storetype BKS -provider org.bouncycastle.jce.provider.BouncyCastleProvider -storepass ‘123456’ 13 cer crt openssl x509 -inform DER -in xxx.cer -out xxx.crt 14 pem crt openssl x509 -outform der -in xxx.pem -out xxx.crt 15 pem cer openssl x509 -inform pem -in xxx.pem -outform der -out xxx.cer 另外:查看 bks 文件中包含的证书keytool -list -rfc -keystore xxx.bks -storetype BKS 查看 jks 文件中包含的证书keytool -list -rfc -keystore xxx.jks -storetype JKS","categories":[{"name":"Android","slug":"Android","permalink":"http://www.dashy.cn/categories/Android/"}],"tags":[{"name":"HTTPS","slug":"HTTPS","permalink":"http://www.dashy.cn/tags/HTTPS/"}],"author":"Dashy"},{"title":"[Ynaqdh]到底是什么意思(what’s the meaning of [Ynadqh])","slug":"[Ynaqdh]到底是什么意思(what’s the meaning of [Ynadqh])","date":"2019-01-05T14:52:00.000Z","updated":"2020-01-08T16:54:39.900Z","comments":true,"path":"2019/01/05/[Ynaqdh]到底是什么意思(what’s the meaning of [Ynadqh])/","link":"","permalink":"http://www.dashy.cn/2019/01/05/[Ynaqdh]%E5%88%B0%E5%BA%95%E6%98%AF%E4%BB%80%E4%B9%88%E6%84%8F%E6%80%9D(what%E2%80%99s%20the%20meaning%20of%20[Ynadqh])/","excerpt":"","text":"使用Mac终端时经常会碰见上图中的提醒 ++[ynaqdh]++ ,下面简单说明一下: Y - yes, overwrite n - no, do not overwrite a - all, overwrite this and all others q - quit, abort d - diff, show the differences between the old and the new h - help, show this help","categories":[],"tags":[],"author":"Dashy"},{"title":"第一行代码总结","slug":"第一行代码总结","date":"2018-12-12T15:04:00.000Z","updated":"2020-01-08T16:54:39.919Z","comments":true,"path":"2018/12/12/第一行代码总结/","link":"","permalink":"http://www.dashy.cn/2018/12/12/%E7%AC%AC%E4%B8%80%E8%A1%8C%E4%BB%A3%E7%A0%81%E6%80%BB%E7%BB%93/","excerpt":"","text":"Android系统架构 为什么使用Log而不是System.out + Activity的基本用法 Activity中如何使用Menu Intent的使用(显示和隐式) 向下(上)一个Activity传递数据 Activity的四种状态,7个方法,3种生存期 Activity被回收了如何保存和恢复数据 Activity的四种启动模式 Activity的实践: 如何知晓当前Activity名称,如何随时退出程序,启动活动的最佳写法 常用系统控件: AlertDialog+构建,ProgressBar的构建 四种基本布局 引入布局,创建自定义控件 提升ListView性能,ListView点击事件 RecyclerView的基本用法(Adapter的编写),实现横向滚动和瀑布式布局 RecyclerView点击事件 Fragment的基本用法: 动态添加fragment(限定符的使用), 模拟返回栈, fragment与Activity之间通信 fragment的生命周期,4种状态,比Activity多了5个回调方法 广播机制简介(标准广播和有序广播) 如何接收广播(动态注册&静态注册) 如何发送广播(标准&有序) 如何使用本地广播 广播实践: 实现强制下线 数据持久化技术1) 如何将数据写入文件中(以及读取)2) 如何将数据存储到SharedPreferences(以及读取)3) SQLite的使用(增删改查)4) LitePal的使用(增删改查) 在程序运行时申请权限 ContentResolver 的基本用法(读取系统联系人) 创建自己的内容提供器ContentProvider Notification 的使用,添加PendingIntent,点击之后消失的功能 Notification 进阶使用: 设置震动,提示音,呼吸灯,大文本,大图,优先级 调用摄像头拍照 从相册中选取照片 播放音频 播放视频 WebView的用法 HttpURLConnection的基本使用 OKHttp的基本使用 解析XML格式数据(PULL解析&SAX解析) 解析JSON格式数据(JSonObjective&Gson) 子线程中更新UI 异步消息处理机制分析 AsyncTask 的基本用法 服务的基本用法,启动和停止服务 活动和服务进行通信 Service 小技巧: 前台服务, IntentService LBS(Location Based Serveice)基本位置的服务1) 确定自己的位置2) 实时更新当前的位置3) 选择定位模式4) 添加省市县位置信息5) 让地图显示出来6) 移动到我的位置7) 让我显示出来 Material Design简介Toolbar的基本用法(添加Menu,点击事件,最左加入一个导航按钮)DrawerLayout 的基本用法(侧滑显示菜单)NavigationView(侧滑菜单,Menu和headerLayout)FloatingActionBar(悬浮按钮)Snackbar(增加Undo按钮)CoordinateLayout(加强版FrameLayout,自动帮助我们做出最为合理的响应)CardView(卡片式布局)APPBarLayout(防止滑动RecyclerView时遮挡Toolbar,该控件必须是CoordinateLayout的子布局)SwipeRefreshLayout(下拉刷新)CollapsingToolbarLayout(可折叠式标题,仅能作为APPBarLayout直接子布局使用) 充分利用系统状态栏 全局获取Context 使用Intent传递对象(Serializable方式和Parcelable方式) 创建定时任务,Alarm机制 Doze模式,多窗口模式 Lambda表达式","categories":[{"name":"Android","slug":"Android","permalink":"http://www.dashy.cn/categories/Android/"}],"tags":[{"name":"Android","slug":"Android","permalink":"http://www.dashy.cn/tags/Android/"}],"author":"Dashy"},{"title":"如何在Mac上卸载Java","slug":"如何在Mac上卸载Java","date":"2018-02-27T15:02:00.000Z","updated":"2020-01-08T16:54:39.915Z","comments":true,"path":"2018/02/27/如何在Mac上卸载Java/","link":"","permalink":"http://www.dashy.cn/2018/02/27/%E5%A6%82%E4%BD%95%E5%9C%A8Mac%E4%B8%8A%E5%8D%B8%E8%BD%BDJava/","excerpt":"","text":"在“终端”窗口中,复制和粘贴命令: sudo rm -fr /Library/Internet\\ Plug-Ins/JavaAppletPlugin.plugin sudo rm -fr /Library/PreferencesPanes/JavaControlPanel.prefPane sudo rm -fr ~/Library/Application\\ Support/Java","categories":[{"name":"Mac","slug":"Mac","permalink":"http://www.dashy.cn/categories/Mac/"}],"tags":[{"name":"Mac","slug":"Mac","permalink":"http://www.dashy.cn/tags/Mac/"}],"author":"Dashy"},{"title":"配置开机自启rails以及chromium","slug":"配置开机自启rails以及chromium","date":"2018-02-06T15:01:00.000Z","updated":"2020-01-08T16:54:39.921Z","comments":true,"path":"2018/02/06/配置开机自启rails以及chromium/","link":"","permalink":"http://www.dashy.cn/2018/02/06/%E9%85%8D%E7%BD%AE%E5%BC%80%E6%9C%BA%E8%87%AA%E5%90%AFrails%E4%BB%A5%E5%8F%8Achromium/","excerpt":"","text":"Stories DashboardTo startup rails and chromium when the raspberry PI startup. Clone repo, open Terminal enter this code clone [email protected]:namiwang/stories-dashboard.git```1234562. **Install gems**, run this lines of codes separately```cd stories-dashboard``` ```bundle Change path, if the path you choose don’t like this /home/pi/workspace/stories-dashboard, you must edit two files in stories-dashboard/app/bin startup change cd /home/pi/workspace/stories-dashboard into /yourpath/stories-dashboard```1234567- rc.local change ~~```su pi -c "exec /home/pi/workspace/stories-dashboard/bin/startup"```~~ into ```su pi -c "exec /yourpath/stories-dashboard/bin/startup" reboot Prohibited raspberry PI sleeping Open Terminal enter this command nanolink12345678910112. Press **"Ctrl + w"** to find ==[Seat:*]==, after this few lines you will see ```# xserver-command=X``` change it into ```xserver-command = X -s 0 -dpms``` it means to Close the screen saver and Display Power Management Signaling.3. > ```reboot","categories":[{"name":"Raspberry Pi","slug":"Raspberry-Pi","permalink":"http://www.dashy.cn/categories/Raspberry-Pi/"}],"tags":[{"name":"Rails","slug":"Rails","permalink":"http://www.dashy.cn/tags/Rails/"},{"name":"Raspberry Pi","slug":"Raspberry-Pi","permalink":"http://www.dashy.cn/tags/Raspberry-Pi/"}],"author":"Dashy"},{"title":"树莓派禁止休眠","slug":"树莓派禁止休眠","date":"2018-02-03T15:00:00.000Z","updated":"2020-01-08T16:54:39.918Z","comments":true,"path":"2018/02/03/树莓派禁止休眠/","link":"","permalink":"http://www.dashy.cn/2018/02/03/%E6%A0%91%E8%8E%93%E6%B4%BE%E7%A6%81%E6%AD%A2%E4%BC%91%E7%9C%A0/","excerpt":"","text":"Prohibited raspberry PI sleeping Open Terminal enter this command nanolink123456789102. Press **"Ctrl + w"** find ==[Seat:*]==, after this few lines you will see ```# xserver-command=X``` change it into ```xserver-command = X -s 0 -dpms``` it means to Close the screen saver and Display Power Management Signaling.3. > ```reboot","categories":[{"name":"Raspberry Pi","slug":"Raspberry-Pi","permalink":"http://www.dashy.cn/categories/Raspberry-Pi/"}],"tags":[{"name":"Raspberry Pi","slug":"Raspberry-Pi","permalink":"http://www.dashy.cn/tags/Raspberry-Pi/"}],"author":"Dashy"},{"title":"树莓派开启启动自定义脚本","slug":"树莓派开启启动","date":"2018-02-01T14:59:00.000Z","updated":"2020-01-08T16:54:39.916Z","comments":true,"path":"2018/02/01/树莓派开启启动/","link":"","permalink":"http://www.dashy.cn/2018/02/01/%E6%A0%91%E8%8E%93%E6%B4%BE%E5%BC%80%E5%90%AF%E5%90%AF%E5%8A%A8/","excerpt":"","text":"nano /etc/rc.local 修改开机启动文件 在 exit 0 这行代码之前添加 su pi -c “exec /home/pi/stories.sh” 编辑启动rails server 和 Chromium 的脚本 #!/bin/sh cd /home/pi/Documents/stories_dashboard source ~/.profile rails s & sleep 15 DISPLAY=:0 chromium-browser -kiosk http://localhost:3000 3.不要忘了修改stories.sh的权限 chmod 777 stories.sh","categories":[{"name":"Raspberry Pi","slug":"Raspberry-Pi","permalink":"http://www.dashy.cn/categories/Raspberry-Pi/"}],"tags":[{"name":"Rails","slug":"Rails","permalink":"http://www.dashy.cn/tags/Rails/"},{"name":"Raspberry Pi","slug":"Raspberry-Pi","permalink":"http://www.dashy.cn/tags/Raspberry-Pi/"}],"author":"Dashy"},{"title":"ror教程(ruby on rails)3","slug":"ror教程(ruby-on-rails)3","date":"2017-12-28T14:57:00.000Z","updated":"2020-01-08T16:54:39.913Z","comments":true,"path":"2017/12/28/ror教程(ruby-on-rails)3/","link":"","permalink":"http://www.dashy.cn/2017/12/28/ror%E6%95%99%E7%A8%8B%EF%BC%88ruby-on-rails%EF%BC%893/","excerpt":"","text":"Hash.new 可接受一个参数指明元素的默认值,即当键不存在时返回的值 12345678>> h = Hash.new=> {}>> h[:foo] # 试图获取不存在的键 :foo 对应的值=> nil>> h = Hash.new(0) # 让不存在的键返回 0 而不是 nil=> {}>> h[:foo]=> 0 在类中调用方法或访问属性时可以不用 self.(赋值例外) Confuse不理解 yieldpbcopy ~/.ssh/id_rsa.pub .card-img-overlay .d-flex.pt-5.pb-3.px-2 .card-text.text-white.pl-2= post.summary tag颜色,动态加载,搜索,排行。 react,flutter。","categories":[{"name":"Rails","slug":"Rails","permalink":"http://www.dashy.cn/categories/Rails/"}],"tags":[{"name":"Rails","slug":"Rails","permalink":"http://www.dashy.cn/tags/Rails/"}],"author":"Dashy"},{"title":"Rails 提示 Looks like your apps bin rails is a stub that was generated by Bund","slug":"Rails-提示-Looks-like-your-apps-bin-rails-is-a-stub-that-was-generated-by-Bund","date":"2017-12-28T14:57:00.000Z","updated":"2020-01-08T16:54:39.899Z","comments":true,"path":"2017/12/28/Rails-提示-Looks-like-your-apps-bin-rails-is-a-stub-that-was-generated-by-Bund/","link":"","permalink":"http://www.dashy.cn/2017/12/28/Rails-%E6%8F%90%E7%A4%BA-Looks-like-your-apps-bin-rails-is-a-stub-that-was-generated-by-Bund/","excerpt":"","text":"Rails 提示 Looks like your app’s ./bin/rails is a stub that was generated by Bundler. 无缘无故的输入rails相关指令出现了一大堆tips,目前还没有影响运行,但是看着很不爽。123456789101112Looks like your app's ./bin/rails is a stub that was generated by Bundler.In Rails 5, your app's bin/ directory contains executables that are versionedlike any other source code, rather than stubs that are generated on demand.Here's how to upgrade: bundle config --delete bin # Turn off Bundler's stub generator rails app:update:bin # Use the new Rails 5 executables git add bin # Add bin/ to source controlYou may need to remove bin/ from your .gitignore as well. 尝试按照其中的提示解决这个问题输入如下指令 1rails app:update:bin 问题完美解决了。","categories":[{"name":"Rails","slug":"Rails","permalink":"http://www.dashy.cn/categories/Rails/"}],"tags":[{"name":"Rails","slug":"Rails","permalink":"http://www.dashy.cn/tags/Rails/"}],"author":"Dashy"},{"title":"rails 提示没有匹配的路由(no route matches)","slug":"rails-提示没有匹配的路由-no-route-matches","date":"2017-12-27T14:55:00.000Z","updated":"2020-01-08T16:54:39.905Z","comments":true,"path":"2017/12/27/rails-提示没有匹配的路由-no-route-matches/","link":"","permalink":"http://www.dashy.cn/2017/12/27/rails-%E6%8F%90%E7%A4%BA%E6%B2%A1%E6%9C%89%E5%8C%B9%E9%85%8D%E7%9A%84%E8%B7%AF%E7%94%B1-no-route-matches/","excerpt":"","text":"No route matches 今天在跟着做 Ruby on Rails 教程第五章的例子时,遇到了一个问题 No route maches 代码如下 最后发现是在path那里多加了单引号导致的,删掉之后完美运行。","categories":[{"name":"Rails","slug":"Rails","permalink":"http://www.dashy.cn/categories/Rails/"}],"tags":[{"name":"Rails","slug":"Rails","permalink":"http://www.dashy.cn/tags/Rails/"}],"author":"Dashy"},{"title":"rails 提示没有匹配的路由(no route matches)","slug":"rails-提示没有匹配的路由-no-route-matches-1","date":"2017-12-27T14:55:00.000Z","updated":"2020-01-08T16:54:39.904Z","comments":true,"path":"2017/12/27/rails-提示没有匹配的路由-no-route-matches-1/","link":"","permalink":"http://www.dashy.cn/2017/12/27/rails-%E6%8F%90%E7%A4%BA%E6%B2%A1%E6%9C%89%E5%8C%B9%E9%85%8D%E7%9A%84%E8%B7%AF%E7%94%B1-no-route-matches-1/","excerpt":"","text":"No route matches 今天在跟着做 Ruby on Rails 教程第五章的例子时,遇到了一个问题 No route maches 代码如下 最后发现是在path那里多加了单引号导致的,删掉之后完美运行。","categories":[{"name":"Rails","slug":"Rails","permalink":"http://www.dashy.cn/categories/Rails/"}],"tags":[{"name":"Rails","slug":"Rails","permalink":"http://www.dashy.cn/tags/Rails/"}],"author":"Dashy"},{"title":"ror教程(ruby on rails)2","slug":"demo","date":"2017-12-27T14:43:00.000Z","updated":"2020-01-08T16:54:39.902Z","comments":true,"path":"2017/12/27/demo/","link":"","permalink":"http://www.dashy.cn/2017/12/27/demo/","excerpt":"","text":"test controller 中可以通过使用setup来初始化一些变量 1234567891011121314151617181920212223242526require 'test_helper'class StaticPagesControllerTest < ActionDispatch::IntegrationTest def setup @base_title = "Ruby on Rails Tutorial Sample App" end test "should get home" do get static_pages_home_url assert_response :success assert_select "title", "Home | #{@base_title}" end test "should get help" do get static_pages_help_url assert_response :success assert_select "title", "Help | #{@base_title}" end test "should get about" do get static_pages_about_url assert_response :success assert_select "title", "About | #{@base_title}" endend 定义和使用变量时不要忘记加 @ 符号 provide 123456789101112131415<% provide(:title, "Home") %><!DOCTYPE html><html> <head> <title><%= yield(:title) %> | Ruby on Rails Tutorial Sample App</title> </head> <body> <h1>Sample App</h1> <p> This is the home page for the <a href="http://www.railstutorial.org/">Ruby on Rails Tutorial</a> sample application. </p> </body></html> provide 与 content_for 区别 The same as content_for but when used with streaming flushes straight back to the layout. In other words, if you want to concatenate several times to the same buffer when rendering a given template, you should use content_for, if not, use provide to tell the layout to stop looking for more contents. not something we can merge 单引号字符串不能进行插值操作 1234567>> string = 'dashy'=> "dashy">> puts "The string '#{string}' is nonempty." if string.empty?=> nil>> puts "The string '#{string}' is nonempty." unless string.empty?The string 'dashy' is nonempty.=> nil 可以使用 !!(读作“bang bang”)对对象做两次取反操作,把对象转换成布尔值 1234>> a = %w[foo bar baz quux]=> ["foo", "bar", "baz", "quux"]>> a[0..2]=> ["foo", "bar", "baz"] 值域的结束值使用 -1 时,不用知道数组的长度就能从起始值开始一直获取到最后一个元素。","categories":[{"name":"Rails","slug":"Rails","permalink":"http://www.dashy.cn/categories/Rails/"}],"tags":[{"name":"Rails","slug":"Rails","permalink":"http://www.dashy.cn/tags/Rails/"}],"author":"Dashy"},{"title":"ror教程(ruby on rails)1","slug":"ror教程(ruby rails)1","date":"2017-12-26T14:42:00.000Z","updated":"2020-01-08T16:54:39.909Z","comments":true,"path":"2017/12/26/ror教程(ruby rails)1/","link":"","permalink":"http://www.dashy.cn/2017/12/26/ror%E6%95%99%E7%A8%8B%EF%BC%88ruby%20rails%EF%BC%891/","excerpt":"","text":"git rm -r –cached . 删除暂存区中的全部文件(未commit 已add) git checkout -f 恢复未add 的文件 scaffold 脚手架生成资源 资源可以理解为model(数据模型)+view(web页面),可以通过http协议在网页中创建、读取、更新和删除。 REST 架构由计算机科学家 Roy Fielding 提出,意思是“表现层状态转化”(Representational State Transfer) REST 是一种架构风格,用于开发分布式、基于网络的系统和软件应用,例如万维网和 Web 应用。REST 理论很抽象,在 Rails 应用中,REST 意味着大多数组件(例如用户和微博)都被模型化,变成资源(resource),可以创建(create)、读取(read)、更新(update)和删除(delete)。这些操作与关系型数据库中的 CRUD 操作和 HTTP 请求方法(POST、GET、PATCH 和 DELETE)对应。","categories":[{"name":"Rails","slug":"Rails","permalink":"http://www.dashy.cn/categories/Rails/"}],"tags":[{"name":"Rails","slug":"Rails","permalink":"http://www.dashy.cn/tags/Rails/"}],"author":"Dashy"},{"title":"BMI 计算器(BMI Calculator)","slug":"BMI 计算器(BMI Calculator)","date":"2017-12-21T14:37:48.000Z","updated":"2020-01-08T16:54:39.895Z","comments":true,"path":"2017/12/21/BMI 计算器(BMI Calculator)/","link":"","permalink":"http://www.dashy.cn/2017/12/21/BMI%20%E8%AE%A1%E7%AE%97%E5%99%A8(BMI%20Calculator)/","excerpt":"","text":"这两天看高見龍老师的为你自己学ruby on rails 教程,其中有一个比较简单的Demo,就是这个BMI Calculator,自己动手跟着实现了一下,顺便写一篇博客记录一下,加深印象。 最终效果如下,输入身高体重点击开始计算后会得出BMI值,UI比较简陋,重要的是理解rails的整个流程。 新建一个rails项目:1rails new bmi 创建控制器(controller) 首先切换到项目 1cd bmi 之后输入如下指令用来创建控制器 123rails generate controller bmi index或者rails g controller bmi index 上面的指令会自动帮助我们做三件事 加上route,打开config/route.rb文件 12345Rails.application.routes.draw do get 'bmi/index' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.htmlend 将其中的 1get 'bmi/index' 改写成 1get 'bmi', to: 'bmi#index' 并且添加 1post "bmi/result", to: "bmi#result" controller中加上名为 index 的 Action打开app/controllers/bmi_controller.rb,其中内容如下 1234class BmiController < ApplicationController def index endend 创建app/views/bmi/index.html.erb文件打开app/views/bmi/index.html.erb,其中内容如下 12<h1>Bmi#index</h1><p>Find me in app/views/bmi/index.html.erb</p> 建立输入表单编辑index.html.erb,将其改为如下内容123456<h1>BMI 计算器</h1><%= form_tag 'bmi/result' do %> 身高: <%= text_field_tag 'body_height' %> 公分<br/> 体重: <%= text_field_tag 'body_weight' %> 公斤<br/> <%= submit_tag '开始计算' %><% end %> form_tag,text_field_tag 和 submit_tag 是 rails 的 TagHelper,可以点进去详细的看一下。 看一下index页面的源码,这些都是刚刚的TagHelper的功劳。 现在输入的表单有了,需要去实现计算BMI的功能,上一步的表单会把数据提交到result的action计算。编辑app/controller/bmi_controller.rb,添加名为result的action1234567891011class BmiController < ApplicationController def index end def result height = params[:body_height].to_f / 100 weight = params[:body_weight].to_f @bmi = (weight/ (height * height)).round(2) endend 计算出的结果需要显示出来,所以我们需要新建一个app/views/bmi/result.html.erb文件1<h1>您的BMI值为: <%= @bmi %> <h1> 现在项目部署一下应该就可以成功运行了~","categories":[],"tags":[{"name":"Rails","slug":"Rails","permalink":"http://www.dashy.cn/tags/Rails/"}]},{"title":"如何重新命名Git分支(how to rename a git branch locally and remotely?","slug":"rename-git-branch","date":"2017-12-15T14:33:15.000Z","updated":"2020-01-08T16:54:39.907Z","comments":true,"path":"2017/12/15/rename-git-branch/","link":"","permalink":"http://www.dashy.cn/2017/12/15/rename-git-branch/","excerpt":"","text":"git branch -m git checkout git push origin git push origin -d 参考自:https://stackoverflow.com/questions/36999937/how-to-rename-a-git-branch-locally-and-remotely++","categories":[],"tags":[{"name":"Git","slug":"Git","permalink":"http://www.dashy.cn/tags/Git/"}]}]}