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
完成.
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.
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"

