2017年1月28日 星期六

bootstrap 導入 rails

由於安裝的時候只gem boostrap-sass
其實全套的bootstrap很大一個,還是去官網下載來試
解開後有css fonts js 三個資料夾
都丟到assets下就好


然後在layout裡的<head>裡加上
<link href="../assets/bootstrap.min.css" rel="stylesheet">


</body>上加上
  <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
     <!-- Include all compiled plugins (below), or include individual files as needed -->
     <script src="../assets/bootstrap.min.js"></script>


主要是為了加carousel ,加上code之後記得去改圖片位置



然後要設定加上這些要記得加在css裡
.carousel-inner > .item > img{
      width: 30%;
      margin: auto;
}



2017年1月21日 星期六

ruby上課記D8

測試完開始用session收尾
加上bootsrap

看來還是要先把ruby弄熟...

2017年1月18日 星期三

ubuntu thinkpad fan noisy

風扇會無緣無故爆衝,找到解決方法 我是T420

sudo apt-get install thinkfan

http://www.thinkwiki.org/wiki/How_to_control_fan_speed
http://thinkwiki.de/Thinkfan

然後因為每次開機都要手動輸入,找了很久之後發現要在/etc/rc.local
加上這列就可以開機自動執行,終於阿終於

echo level 2 | sudo tee /proc/acpi/ibm/fan

Rails db操作 update

由於要update資料不會打語法,找到這篇
http://guides.rubyonrails.org/active_record_basics.html
中文版
http://rails.ruby.tw/active_record_basics.html

其實英文版的就夠啦..

相關說明
http://punk.tw/2007/09/15/rails%E5%AD%B8%E7%BF%92%E5%BF%83%E5%BE%97-activerecord%EF%BC%9A%E5%AD%98%E5%8F%96%E8%B3%87%E6%96%99%E5%BA%AB%E4%B8%8D%E7%94%A8%E5%AF%ABsql%E8%AA%9E%E6%B3%95%EF%BC%9F/

ubuntu16.04 git deploy on heroku error solutions

after I add the gem 'pg' to the gemfile
and run bundle
still error!!
 
cmd line type this $sudo apt-get install libpq-dev  
bundle installed 

git init
git add .
git commit -m "First commit"
heroku create 
and git push heroku master is sucess. 
but the page wasn't show.
 
I read the log,it shows table error, 
 
heroku run rake db:migrate
 
done.finally. 

2017年1月16日 星期一

Ruby上課記D6

竟然忘了寫,今天上了投票功能,使用render partial:的功能,判斷式儘量寫在model裡

中間卡了一個很大的關是方法設vote_candidate_path的method,結果action找不到路徑,去routes加了put :vote, on: :member才好

票數統計

Store與Rroduct的關聯,使用多對多

HATBM
要記得新建table

還有SCOPE功能

寄信通知mailer的設定

Ruby上課記D5

S1
RSPEC
打入let (:bank) {BankAccount.new(10)}後 下面的可以拿掉


2017年1月13日 星期五

Learn ruby the hard way 自學心得

https://learnrubythehardway.org/book/

由於學了rails發現實在太容易卡關,想了想還是回來一條一條刻,畢竟如果以後要寫,卡關是沒人可以救你的,還是要自己學會游泳的方法 

只記卡關的地方和重點
:E2 檢查每條程式行理解並在上面註解,這非常重要。
:E3 運算子及浮點數4.0
:E5 變數在字串中使用#{}
:E6 "" '' 的用法
:E7 #{}中使用字串要加''
:E8 %{}   #{}  的用法
:E9\n  %q的用法
:E10 \n \t \\
:E11 gets方法後的chomp可以去除掉換行字元
:E12 to_i, to_f
:E13 ARGV, unpack, 
:E14 使用ARGV, $stdin.gets.chomp
:E15 get.chomp irb  這堂很重要 
:E16 寫入檔案 open, write, read
:E17 複製內容到另一個新檔案
:E18 def function () end 
:E19 function實作
:E20 seek的用法 



:E21 function的應用 function(function())
:E22 review "", #{}, .to_f, =, %{}, %q{}, \t\n\\, gets.chomp, $stdin.gets.chomp, ARGV, IO open,  

:E23 閱讀code , carrierwave , [include,module,require    ?]
:E24 <<END called heredoc
:E25 Ex25 module名可以存成Ex29.rb
:E26 改錯字
:E27 ||or, !not, !(true&&false)=true,!(true||false)=false
:E28 when boolean true return first operands
:E29 if..end
:E30 syntax error means 少了end, block, elsif
:E31 set a logic game
:E32 array, <<, for in, each do,
:E33 numbers.each do |fruit|
         puts "#{fruit}"
         end

         可以簡寫成 numbers.each { |n| puts n }
後面要改寫成function呼叫,我竟然卡關了...
:E34 ordinal 順序數, cardinal 幾個數
:E35 可以改成這樣判斷是否是數字   if choice =~ /[0-9]/
:E36 練習練習再練習
:E37 練習讀程式碼
:E38 stuff.push("hello") = push(stuff, "hello")
:E39 only use numbers to get items in Array, Hash用法 key => value
:E40 initialize的用法,@  蠻重要的

2017年1月12日 星期四

Ruby上課記D4

TDD

RSpec

uninitialized constant

http://ithelp.ithome.com.tw/articles/10159403

http://ithelp.ithome.com.tw/articles/10158912

2017年1月9日 星期一

Bootstrap用後的差別

想看看到底bootstrap有什麼作用
安裝之後改了index.html
<table class = "table table-hover"> 變這樣

原本這樣

atom 開啟專案資料夾

每次開啟atom總是會到根目錄下,然後又要下拉很久才可以找到資料夾,在找了解答許久之後,沒有package可以用

但倒是找到了一個答案,就是在終端機下打 atom .
即可開始atom在該專案資料夾下,也算是解燃眉之急啦

2017年1月8日 星期日

Ruby上學記D3

s1
block概念
yield
實體變數


 實體方法

singleton method
類別方法

S2
superclass :看類別上一層類別
class : 看實體所屬類別
module :模組
include :類別擴充模組

Ruby Object Module

Puclic, Private, Protect

S3
moudle與class 的差別 : module不能new 跟繼承

S4
慣例產生複數資料夾
SCSS

JavaScript Hoisting提昇
ES6
Gem: kaminari
Gem :devise

S5
Migration
add column
Gem: Hirb-unicode
Gem: byebug
render text

S6
rails g migration add_cover_image_to_posts  cover_image
Gem :carrierwave
Gem :simple_form
Strong parameter強參數的寫法
Gem: minimagick 縮圖

Git 

http://violin-tao.blogspot.tw/2015/04/ror-week4-railsbootstrap.html 

simple_form修改 f.input
 fox/app/views/fruits/_form.html.erb

 bootstrap 滑鼠hover取消在
fox/app/assets/stylesheets/scaffolds.scss 尋找hover刪掉

S7 Carrierwave
新增欄位輸入出現error
Unpermitted parameter: price
在app/controllers/fruits_controller.rb找最下面的白名單
 顯示圖片使用 image_tag(source, options={}) public
http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/image_tag


疑問 view裡的index 跟show裡面的fruit一個有加@一個沒加
用migration指令即可增加欄位? 及如何修改新增欄位等


S8 安裝devise
 github上的講的不是很清楚,順序應是 [gem devise install], 之後再[rails g devise:install]
[rails g devise xxxxx],後會產生新|xxxxx|model及table,再來[rails g devise:view]後會生出一堆檔案供客製化,[rails db:migrate],名字設定route指向index,之後migration新增欄位及打開白名單,大致上完成

https://ihower.tw/rails/auth.html 
http://rails101s.logdown.com/posts/247881-20-4-adding-user-functions 

2017年1月7日 星期六

Ruby上學記D2

db:migrate
手機應用程式 json檔

.erb  =的用法
rails console
blog 應用程式
外部鍵
model下設定
API
常數大寫字母開頭
冒號開頭 視為『物件』
ARRAY與HASH的差別

each do
map
reduce

2017年1月4日 星期三

Ruby上學記D1

今天終於開始上課了,帶著不安的心情,開始學程式語言,一到教室,8位有5位用APPLE,作業環境單一果然還是很重要的。
今天主要是安裝環境,雖然我有備而來的安裝了UBUNTU,在安裝時中還是頻頻出現ERROR,1.先從安裝的時候需要設定LOGIN,2.是安裝RAILS的時候又出現錯誤,3.是RAILS網頁的時候又要叫我安裝NODEJS,4.在安裝RVM時竟然還出現不符UBUNTU套件的ERROR,這些問題還好是在教室發生,要是自學身份一定會被這些鳥問題又搞到頭很大,還好有老師在,光這些問題就讓我覺得值得了....,一度讓我想說乾脆換電腦算了,連會自動APT-GET的UBUNTU都快搞死我了,奉勸各位千萬別用WINDOWS學,雖然我用UBUNTU都很想死了。

Ruby,RVM,gem,rail,scafford

##RVM is not a function, selecting rubies with 'rvm use ...' will not work.