2016年9月27日 星期二
2016年9月25日 星期日
2016年9月23日 星期五
[Rails]simple_form 錯誤 error -undefined method 'number?'
undefined method 'number?' for #<ActiveRecord::ConnectionAdapters::PostgreSQLColumn:0x007fd89fda3d40>
解決方法>> 更改你的Gemfile
gem 'simple_form'
to
gem 'simple_form', github: 'kesha-antonov/simple_form', branch: 'rails-5-0'
然後bundle install,重開server Done
2016年9月22日 星期四
[文字編輯器]Sublime Text好用套件-Emmet
手動安裝可參考 :https://www.minwt.com/webdesign-dev/html/11624.html
這邊使用的是sublime2
安裝步驟
1.下載Sublime Text https://www.sublimetext.com/3
2.安裝Package Control
2-1開啟sublime 並開啟Console (位置在最上方的view > Show Console可以看到下方出現console
2-2 輸入相對版本的指令 https://sublime.wbond.net/installation
Sublime Text 2
import urllib2,os,hashlib; h = '261dd1222b4693ce6d4f85f9c827ac06' + '6d5ab8ebdd020086947172a8a1356bb6'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); os.makedirs( ipp ) if not os.path.exists(ipp) else None; urllib2.install_opener( urllib2.build_opener( urllib2.ProxyHandler()) ); by = urllib2.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); open( os.path.join( ipp, pf), 'wb' ).write(by) if dh == h else None; print('Error validating download (got %s instead of %s), please try manual install' % (dh, h) if dh != h else 'Please restart Sublime Text to finish installation')2-3 重開
3.安裝Emmet
3-1 開啟package controller (Sublime Text2 > perferences >Package Control)
或快捷鍵(command+shift+p)
3-2 選擇 Package Control:Install Package
選擇第一個( 並非我途中所顯示的那個,因為我已經安裝所以不會顯示)
這個才是正確的Emmet (youtube 截圖 from :https://www.youtube.com/watch?v=8n923UBjV9w)
3-4重開 !!完成
再來是操作 ,在sublime 開啟 html檔案,以下是簡易的教學影片
輸入 .[class name] 後,按鍵盤的Tab鍵 即可變成
<div class="[class name]"></div>
幫你省下許多時間
更多外掛介紹及教學
http://www.slideshare.net/banPrint/sublime-text-51689543
2016年9月21日 星期三
2016年9月19日 星期一
[Ruby on Rails]上傳app到 Heroku
出處:http://railsgirls.tw/heroku
取得 Heroku
按照 Heroku 官方的快速上手指南的步驟 1 至步驟 3,來註冊、安裝工具包並登入。
教練: 講解將 App 部署到 Heroku,跟傳統自己架伺服器比起來,有什麼好處。
準備妳的 app
版本管理系統
需要把程式碼加到版本管理系統。在終端機裡輸入以下命令:
git init
echo "public/uploads" >> .gitignore
echo "tmp" >> .gitignore
echo "logs" >> .gitignore
git add .
git commit -m "initial commit"
教練:講解使用版本管理系統的好時機。順便解釋
.gitignore 檔案是什麼,並解釋為什麼要忽略某些檔案被傳上去。更新資料庫
首先,需要讓資料庫在 Heroku 跑起來。Heroku 使用不同於 Rails 預設的資料庫。請修改 Gemfile 的內容:
請將
gem 'sqlite3'
改為
group :development do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
執行
bundle install --without production 命令來解決軟體相依問題。
教練: 可以講講 RDBMS 以及 pg 與 sqlite 的差別,請講點 Heroku 的 PostgreSQL 軟體相依細節。
安裝 rails_12factor Gem
接下來,需要在
Gemfile 加入 rails_12factor,讓我們的 app 可以出現在 Heroku。
這個 Gem 調整妳的 Rails App 成為適合在 Heroku 工作的模式,舉例來說,記錄檔存放的地方、靜態檔案的設定(圖片、樣式表以及 JavaScript 檔案)會設定成適合 Heroku 系統的設定。
請修改
Gemfile 的內容:
將
group :production do
gem 'pg'
end
改為
group :production do
gem 'pg'
gem 'rails_12factor'
end
修改好之後到終端機執行
bundle 命令,接著將 Gemfile.lock 提交到妳的程式碼倉庫 (repository):git commit -a -m "Added rails_12factor gem and updated Gemfile.lock"
教練: 可以說說 Heroku 的記錄檔怎麼用,或是其它相關的東西。
部署 App
建立 App
需要在終端裡輸入
heroku create,在 Heroku 上產生一個新的 Heroku app,妳會看到像是下面的訊息:Creating evening-sky-7498... done, stack is cedar
http://evening-sky-7498.herokuapp.com/ | git@heroku.com:evening-sky-7498.git
Git remote heroku added
上面的 “evening-sky-7498” 就是妳 Heroku App 的名稱。
上傳程式碼
接著需要將程式碼上傳至 Heroku,輸入
git push heroku master。妳會看到像是下面的輸出:Counting objects: 134, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (115/115), done.
Writing objects: 100% (134/134), 35.29 KiB, done.
Total 134 (delta 26), reused 0 (delta 0)
-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.1.2
Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ --deployment
Fetching gem metadata from https://rubygems.org/.......
...
-----> Launching... done, v4
http://evening-sky-7498.herokuapp.com deployed to Heroku
看到 “Launching…” 的訊息表示 App 已經上傳完畢了。
資料庫遷移
接著需要遷移資料庫,跟我們在工作坊時,在自己電腦上做的一樣:
heroku run rake db:migrate。
當這條命令執行完畢時,妳可以用產生出來的網址來訪問妳的 App,可以打開這個頁面 http://evening-sky-7498.herokuapp.com/ 看看。也可以在終端裡輸入
heroku open 來開啟網頁。
訂閱:
文章 (Atom)





