Ruby on Rails with Uploadify
在檔案批次上傳最早是使用Swf_upload. 但由於很難修改裡面的一些東西,而且只針對Flash.
後來尋找了一下,Plupload及Uploadify看起來比較好,有支援Falsh,SilverLight,Html5,Html4...etc
所以改用Plupload,"看起來"很好用,但實際上有一堆神秘的Bug.
最後改用Uploadify,雖然一樣有bug,但是都有解法.
最佳解法請參考 : http://railsfun.tw/viewthread.php?tid=257
其中在使用UploadifySettings時,遇到 InvalidAuthenticityToken的問題,這是Uploadify本身的問題.
解法很簡單,卻花我很多時間...
在被init的物件內加上 style='display:block;' 即可.
比如
--官方網展
http://www.uploadify.com/
--其他參考資料
1. http://railstips.org/2009/7/21/uploadify-and-rails23
2. http://jetpackweb.com/blog/2009/ ... degrade-gracefully/
Heroku send by Gmail
在Rails上透過Gmail寄信是蠻簡單的.
但網站搬到Heroku後最近發現似乎寄信有問題?
一查之下才知道要裝套件,官方網站其實就有,不過自己還是做個紀錄.
1.Install Plugin
$ script/plugin install git://github.com/adamwiggins/gmail_smtp.git
2.設定帳號
$ export GMAIL_SMTP_USER=username@gmail.com $ export GMAIL_SMTP_PASSWORD=yourpassword
3.設定Heroku
$ heroku config:add GMAIL_SMTP_USER=username@gmail.com $ heroku config:add GMAIL_SMTP_PASSWORD=yourpassword
完成.
搬移專案到Heroku. 疑難雜症.
原本使用Hosting Rails. 最近因為官方升級,很多問題.
做為一個主機商,一兩天就算了. 一週實在太超過.
版上抱怨也都得沒到解決,發Email連收也沒收到,只差沒打電話..
怕SliceHost也會有類似問題,而且也是一次先預付..索性將專案搬移到Heroku. 使用量到才需要付多一點.
過程遇到一些問題,紀錄一下.
ssh-key問題 :
$ heroku clone hobocookbook [/Data/Rails] [DrTeeth] Initialized empty Git repository in /Data/Rails/hobocookbook/.git/ The authenticity of host 'heroku.com (75.101.141.116)' can't be established. RSA key fingerprint is 8b:48:5e:67:0e:c9:16:47:32:f2:87:0c:1f:c8:60:ad. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'heroku.com,75.101.141.116' (RSA) to the list of known hosts. Permission denied (publickey). fatal: The remote end hung up unexpectedly ...以下省略
解法 :
heroku keys:clear; sudo ssh-keygen -t rsa; heroku keys:add /root/.ssh/id_rsa.pub
然後再做你原本想做的事情.
taps (for Database Upload) 問題 :
~$ sudo gem install taps
[sudo] password for mike:
Building native extensions. This could take a while…
ERROR: Error installing taps:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.8 extconf.rb install taps
checking for fdatasync() in -lrt… yes
checking for sqlite3.h… no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
–with-opt-dir
–without-opt-dir
–with-opt-include
–without-opt-include=${opt-dir}/include
...以下省略
解法 :
sudo aptitude install libsqlite3-dev libsqlite3-doc
taps 無法上傳 :
$ heroku db:push "~/xxx/db/xxx.sqlite3" Loaded Taps v0.3.5 Warning: Data in the app 'xxx' will be overwritten and will not be recoverable. Are you sure you wish to continue? (y/n)? y Failed to connect to database: ArgumentError -> interning empty string
解法 :
heroku db:push --app yourappname
這個最蝦. - -
Power Language In Sniper IDE (H.T.S)
偶然的機會使用到Sniper IDE.真的是最不好用的IDE....
如果想在HTS內把自己的想法實現,除了內建的一些指標,寫好的功能,可能就得使用SniperIDE了.
SniperIDE所使用的Power Language是類似VB的語言,但有少許不同.
但幾乎找不太到文件,也許該歸功於引進公司? 還是這語言太冷門? 還是我不會查?
稍微查了一下,SniperIDE應該不只用在HTS上,似乎來自日本較多....
一些基本語法 : http://tw.myblog.yahoo.com/jw!lbDyLRWQEQV_5hHZAYRp4oPJyg--/article?mid=67&prev=71&next=52
寫慣了Ruby,OO語言. 回去寫這種語言真的蠻痛苦的.
因為本身不甚了解金融,解說一下觀念 :
若 4000->左方欄->SniperTool->SniperIDE(程式語言)->檔案->新增
則會顯示視窗.選擇你要哪一種. 共五種,依照類型不同,也會有不同的限制.
我用到的只有
指標->K棒
函數->自己寫好的,可能是計算開高收低,又或其他. 基本上,內建寫好的函數也是用SniperIDE去寫.
剩的 沒試過.. 若你有試過.. 歡迎指教.
若寫在指標,則該程式會針對"每一個K棒"做處理.
假設你寫
AlertEnabled
if Time<090000 then
Alert("XXX")
end if
則,在09:00之前的所有K棒都會alert.
剛開始還沒會意過來,還以為像OO語法,一直要找K棒的本身.
比如 K.text="" K.color=""
過了好一陣子,我才會意到,面對的是非"OO"語言....
儘管自己將所需資訊輸出,並使用Ruby做分析..
不過,也幾乎把所有在"函數視窗"裡的東西都看了一遍..
幾個比較重要的.
1. FileAppend(pathto, string) 讓你脫離苦海的好東西.
不過,FileAppend有一個缺點.
如果你在IDE內檢驗(Alt+F再按V),則會發現檔案輸出一次.
再一次,卻發現檔案並非被覆蓋,而是直接新增到現有檔案. 也就是同一份檔案有兩份一模一樣的姿料.
這很愚蠢. 這意味著,你每次開啟載入有FileAppend的外掛,他都會Output File一次.... 還不是Replace...
如果沒注意,File可能就會變成x Mb. 甚至xxMb.....
但是SniperIDE開放的功能又少得可憐..
待續....
Productive Ruby on Rails
這陣子一直忙於專案.
之前的專案沒有使用Restful,於是寫起來有點辛苦,也不好整理.
這個專案一開始便使用Restful,配合Scaffold寫起來真的很快....
雖然,這是眾所皆知的東西了,但還是想紀錄一下.. :$
這是寫在Facebook上的文章,懶得重翻,將就一下囉.
英文不好請見諒. :p
I know why everybody say Ruby on Rails is productive now.
As most of parts, Ruby on Rails is there for you.
The only thing you need to do is just type some command and change some works.
For example. "Scaffold" is one of great tool that generate ready to go model for you.
In the one going project ,I scaffolded 4 times for all CRUD works.
Each scaffold for one set of CRUD, and it's ready with Restful style.
Only thing you need to do is build views and setting up some routes, some relationship between databases, and do a little bit work for your controller.
If you don't know what is Restful, and tried to understand how does scaffold works, it might drive you crazy.
Official docs guide you in pretty clear way : This
As others like iHower's PPT : This
And this : This
They all provide lots of information.
How easy if you go with Restful?
Sometimes,we want to create some relationship in this way : " find A user's POST "
In old way, you might create another action called "search post", and have lots of conditions in.
Maybe "find POST by user name", "find POST by comment".... as you can image, that will be lots of work to do.
In Restful way. you only need to set up relationship in routes like :
map.resources :users, :has_many=>{:posts,:comments}
then go into your each controller action "index" and add something like :
@post=find(:all,:conditions=>["user_id=?",params[:user_id]]) if params[:user_id]!=nil
then, when you type address like " users/1/posts/ " , it will show all posts by user_id 1 for u.
Cool, isn't it?
If you have further question, welcome discuss with me.
Shift to Xubuntu
Ubuntu有好多版本.
你知道差別嗎,你最喜歡哪個?
我最喜歡Xubuntu. 因為他快.
Ubuntu有點慢,即使桌面特效全關. 尤其升9.10後(有人知道為什麼嗎?)
Xubuntu很快,開機動畫我也喜歡. 很穩定.
Kubuntu自從9.04?之後,桌面改得亂七八糟,一堆Widget. 就不想用了....
你呢?
小抱怨,Linux上的FF怎麼那麼爛... 很慢.. 尤其開Facebook.. 整個就是 慢速播放*8倍...
又懶得花時間去搞..
Really need to edit the theme of this blog….
嗯. 很久沒有寫.. 真的得花時間整理整理這個blog.
除了改一改Theme,Css. 還得多補充一點內容.
等下個月. 開發到一段落.比較不那麼忙時..
話說,誰說寫網頁很簡單. 一堆雞毛的事....
當然也一堆Trick & Security Issue.
除非只是做個公司形象網站那種的,另當別論.
不過..
要這樣講的話,寫應用程式很簡單.
只是拉一拉方塊,寫一寫對應,一個簡單的計算機10分鐘就出來了.
要這樣講的話,做業務很簡單.
只是話講一講,喝個茶,出一張嘴.
要這樣講的話,做行銷也很簡單.
只是SEO弄一弄,企劃打一打,圖弄一弄
搖搖叫一叫(是叫來演出廣告...:p)
要這樣講的話,做美工也很簡單.
只是線拉一拉,圖貼上剪下,淡化一下,調一下色
最多拍個照片,修一修就好了
但是,從來都不是那麼簡單.
任何事,都不要小看.
Q101 on Ubuntu
3G網卡要在Linux驅動是很麻煩的一件事.
9.10前的版本更是麻煩,得設定,還得寫script.
9.10後就有更快地作法了.
按Alt+F2,輸入gksudo gedit /etc/udev/rules.d/30-q101.rules後,按執行
把以下內容貼進去
# # first, q101 will be detected as usb_storage of 0408:1000 # you have to force it suspend to change running mode from # storage to 3.5g card
SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", ACTION=="add", ATTRS{idVendor}=="0408", ATTRS{idProduct}=="1000", RUN+="/bin/sh -c 'cd /sys$env{DEVPATH};until test -f power/level;do cd ..;done;if [ -f power/level ];then echo suspend > power/level;fi'"
存檔後重開機
插入網卡過幾秒應該就可以看到,選TW Mobile.
Edit Connection:
Number: *99# Username: username password: passwd APN: Internet
(重開)即可.
關於HostingRails Domain
最近都在弄Domain的東西.
有鑑於上次有忘記怎麼弄,還去查官方說明,所以紀錄一下.
若多個指向一個(原本預設之根目錄),則去ParkDomain新增即可.
若指向非預設資料夾,則去AddonDomain新增.
Heroku is a great host for RoR. But still has some problems
Heroku的簡便,其實也造就了他的問題.
因為不是第一次被人推薦了,所以就去官網上看看.
不過,看了就覺得並不是太想用.
除了價格昂貴,再來就是他的優點,其實也是缺點.
Heroku的優點是兩面刃
由於你只要註冊好Heroku,然後 :
sudo gem install heroku
heroku create yourapp
當你要建好專案要上傳 :
git push heroku
就上傳好了
當要做些工作,比如migrate :
heroku domains:add yourdomain.com #(加網域名,應該是加到DNS?) heroku rake db:migrate heroku bundles:capture
可是,他的方便也是不便.
我是不太喜歡一直和Host方溝通,比較喜歡一次就擁有很多自主權.
所以,當有問題,我該寫信去???
問題1, 如果想增加sub domain? 更改MX records,CName,etc...?
問題2, 原先配置為Thin+Nginx. 若想改用其他?
問題3, 目前尚未支援Custom SSL.
問題4, 太貴....
問題5, 還沒想到. 如果你有解答,歡迎討論互動.
就像Xdite說的,在我看來,現在還是Project比較適合. 若要Production,太貴,也不太適合.
--後記 :
初碰Heroku可能面臨問題.
Q : Install?
A : $>sudo gem install heroku
Q : Create?
A : $>git init
$>heroku create
Q : Upload?
A : $>git push heroku YouBranchName(master)
Q : See?
A : $>heroku open
Q : No ssh public key found in /root/.ssh/id_[rd]sa.pub. You may want to specify the full path to the keyfile.
A : ssh-keygen -t rsa
Q : Move Database?
A : $>sudo gem install taps
$>heroku db:push
Q : Rename App?
A : $>git remote rm heroku
$>git remote add git@heroku.com:YOURAPPNAME.git
Q : Manage Custom Gems?
A : 1. Create a file ".gems" under folder
2. Add "yourgem --version x.x.x --source xxxxxxxx" (ex : geokit --version '>=1.5.0' )
Each Gem one line.
3. "git commit -a" & "git push heroku xxx"

