2008年8月29日 星期五

使用scaffold心得

通常初學者在學習使用ror的時候都會使用scaffold來幫助建構出網頁的框架
但是從rails 2.0開始ror就沒有內建scaffold的套件啦
所以必須另外安裝動態scaffold

ruby script/plugin install http://dev.rubyonrails.com/svn/rails/plugins/scaffolding/


又因為動態scaffold會用到內建分頁,而內建分頁功能也被拿掉成為外掛
所以要安裝pagination

ruby script/plugin install svn://errtheblog.com/svn/plugins/classic_pagination


參考來源:
http://blog.pbg4.org/2007/12/20/upgrade-to-rails-2-0-2

因為靜態scaffold的用法與之前的不一樣了
所以如果要使用scaffold來配置你的網頁
必須按照底下的格式使用
ruby script/generate scaffold ModelName [field:type, field:type]

舉個例子
ruby script/generate scaffold product title:string description:text image_url:string

接著就可以到http://your_host/product/
觀看你新架好的網頁

參考來源:
http://topic.csdn.net/u/20070513/22/5931d7c7-7451-4cc3-9dc5-ca3afbb0cae8.html

此外,有在看"agile web development with Rails 2/e"的人可以參考底下網址:
http://agilewebror2.blogspot.com/2008/08/chapter-6.html
他有探討rails 2.0的一些改變

2008年8月26日 星期二

在vim上開發ruby on rails

要讓vim看的懂ruby
其實只要下載ruby.vim就可以了
不過vim的功能可沒有這麼簡單而己哦
只要配合rails.vim和project.vim
就可以讓你的vim瞬間變成功能超強的IDE
可以參考
http://blog.roodo.com/poga/archives/2667806.html

底下是自己安裝的心得
因為我是在Ubuntu 8.04下使用
所以我主要是將檔案存在我自己的家目錄下

step1 下載 rails.vim

請先下載 rails.vim
下載完解壓縮到~/.vim/底下

step2 下載project

接著下載 project
一樣解壓縮到~/.vim/底下

接著就可以開個ruby的檔試試看啦
詳細的操作方法請到參考下列網頁

參考網址:
http://blog.ntut.idv.tw/2007/12/fbsd-vim-ruby-on-rails.html
http://wiki.rubyonrails.org/rails/pages/HowtoUseVimWithRails
http://www.upulife.com/leo/?p=191
http://lightyror.thegiive.net/2007/06/vim-ruby.html
http://devpoga.wordpress.com/2008/02/05/vim-rails/
http://yueguangyuan.javaeye.com/blog/57263

2008年8月24日 星期日

Ubuntu 8.04灌ruby on rails

參考來源:
https://help.ubuntu.com/community/RubyOnRails

Step1 安裝Apache
首先安裝Apache
在commond line底下輸入
sudo apt-get install ruby-full build-essential apache2 apache2-mpm-prefork apache2-prefork-dev


Step2 安裝RubyGems 1.1.0
目前gems已經出到1.2.0了
之前有人說1.2.0有些許的問題
不過我測試的結果 似乎可以直接使用了
指令如下
wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz
tar xzvf rubygems-1.2.0.tgz
cd rubygems-1.2.0
sudo ruby setup.rb
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem
sudo gem update --system


升級完了之後再灌rails
sudo gem install rails
sudo gem install passenger
sudo passenger-install-apache2-module


Step3 修改apache設定檔

最後在/etc/apache2/httpd.conf
加入
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3
PassengerRuby /usr/bin/ruby1.8



寫了幾個測試程式
一直出現
No such file or directory - /tmp/mysql.sock

這是因為Rails 預設會去找 /tmp/mysql.sock 檔,
不過 Debian 或者 Ubuntu 上的 Mysql 卻不是在/tmp/底下,
通常是在 /var/run/mysqld/mysqld.sock,
所以需要改 database.yml,
如下:
development:
adapter: mysql
socket: /var/run/mysqld/mysqld.sock
database: test_development
username: xyz
password: xxxx
host: localhost

這樣改完就可以看到測試的程式

參考來源:
http://blog.roodo.com/syshen/archives/2143083.html

2008年8月19日 星期二

讓你的Gvim也可以compile latex

回國之後我都是用Texmaker編寫我的論文,但是Texmaker用起來總是卡卡的
讓人覺得好像看得很不順眼,而且他的spell checking 也不是很直覺
用起來一整個不順,拼錯字了自己也不知道

後來我發現原來Gvim有內建拼字檢查,這真的是我的救星丫
反正我本來就滿習慣用vim的,而且vim本身就滿好用的
對我來說真的是個好消息

不過還有一個問題就是編好的latex檔要怎麼compile丫??
難不成還要我再開texmaker compile剛才用vim編寫好的tex檔嗎?
當然不用啦
只要灌好vim-latex這個套件
我的Vim就可以幫我compile剛編好的tex檔

Vim-latex的官方網站:
http://vim-latex.sourceforge.net/

安裝有四個步驟:
Step1

先到
http://vim-latex.sourceforge.net/index.php?subject=download&title=Download
下載vim-latex套件

Step2
下載回來之後解壓縮到 C:\Program Files\Vim\vimfiles\

Step3
修改你的
C:\Program Files\Vim\_vimrc
加入

" REQUIRED. This makes vim invoke Latex-Suite when you open a tex file.
filetype plugin on
" IMPORTANT: win32 users will need to have 'shellslash' set so that latex
" can be called correctly.
set shellslash
" IMPORTANT: grep will sometimes skip displaying the file name if you
" search in a singe file. This will confuse Latex-Suite. Set your grep
" program to always generate a file-name.
set grepprg=grep\ -nH\ $*
" OPTIONAL: This enables automatic indentation as you type.
filetype indent on
" OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to
" 'plaintex' instead of 'tex', which results in vim-latex not being loaded.
" The following changes the default filetype back to 'tex':
let g:tex_flavor='latex'


不過我自己試的結果
好像有沒有加這一行都沒有差耶
請參考
http://vim-latex.sourceforge.net/documentation/latex-suite/recommended-settings.html
這樣設定完就可以看到Gvim上多了一些選項可以點選,像是latex常用的符號之類的東西

================================================
灌好vim-latex之後,只要在常態模式之下按\ll
vim就會自動幫你compile你的tex檔
但是它預設是compile成dvi檔
如果想到得到pdf檔
可以點選 TeX-suite > Target format
將dvi改成pdf

不過這樣compile出來的pdf檔圖片會顯示不出來
最好是依序compile dvi > ps > pdf
當然我不會想自己手動這麼作
只要自己新增一個
C:\Program Files\Vim\vimfiles\ftplugin\tex.vim

並在裡面加入

let g:Tex_FormatDependency_pdf = 'dvi,ps,pdf'
let g:Tex_CompileRule_dvi = 'latex --interaction=nonstopmode $*'
let g:Tex_CompileRule_ps = 'dvips -Ppdf -o $*.ps $*.dvi'
let g:Tex_CompileRule_pdf = 'ps2pdf $*.ps'


之後要compile成pdf的時候,就只要按下\ll
一切就完成啦

此外如果想要預設compile成pdf檔的話
只要再剛才的
C:\Program Files\Vim\vimfiles\ftplugin\tex.vim
檔案中加入

let g:Tex_DefaultTargetFormat = 'pdf'


預設產生的檔案就是pdf檔啦
不用每次開檔還要重新設定

參考來源:
http://vim-latex.sourceforge.net/documentation/latex-suite/customizing-latex-suite.html
http://vim-latex.sourceforge.net/documentation/latex-suite/compiler-dependency.html
http://vim-latex.sourceforge.net/documentation/latex-suite/customizing-compiling.html

================================================
此外,如果想要自行設定Windows 的 Gvim 背景色彩
可以參考:
http://blog.longwin.com.tw/archives/000056.html

2008年8月14日 星期四

設定圖檔的bounding box

之前已經提過如何在latex中插入eps圖檔
http://hdj-berkeley.blogspot.com/2008/08/latex-eps.html

要是我插入的圖檔檔案太大了怎麼辦呢?
很簡單,在引入時圖檔時設定好這張圖的bound box就OK啦
\begin{figure}
\centering
\includegraphics[bb= x1 y1 x2 y2, width=0.3]{XXX.eps}
\caption{This is test!}
\label{fig:test}
\end{figure}

其中的x1,y1就是圖檔左下的坐標,x2,y2是圖檔右上的坐標。
所以只要設定好這四個參數就可以繪出你想要的範圍。
但是,要怎麼知道這四個參數呢?
最簡單的方法就是用GSview打開你的eps圖檔,把滑鼠移到你想要裁切的左下角,
這個時候GSview的下方就會出現他的坐標,同理,就可以得到他右上角的坐標。

延申閱讀:
http://www.jijiao.com.cn/TeX/FAQs/00000013.htm
http://www.physics.ohio-state.edu/~faqomatic/fom-serve/cache/105.html

在latex 插入eps檔

由於IEEE要求所有的圖都必須是向量圖
所以,只好乖乖的把所有的圖轉成eps檔
什麼是eps檔呢?
其實我也不是很清楚
有興趣的人可以參考
http://forum.slime.com.tw/post1791992-3.html

不管知不知道eps是什麼,現在的重點是如何將我原來的圖檔轉成eps
其實網路上有很多人在討論如:
http://office.microsoft.com/zh-tw/publisher/HP062079971028.aspx
http://blog.bs2.to/post/icq/12551
http://jrgemini.blogspot.com/2008/07/epslatex.html

原則上,都是用使用內建的印表機,將要輸出的圖檔列印出來,
,然後記得勾選「列印至檔案」這個選項,然後按下列印,
接著會出現一個對話框,詢問檔案要儲存的地方,這樣就可以得到一個ps檔

咦!!怎麼會是ps檔!!!
沒錯,因為由印表機的driver印出來的檔案就是ps檔,如果要得到eps檔必須再使用其他的軟體轉。
以下提供三種轉檔的方法:

方法一 使用GSview
首先用GSview打開剛才儲存的ps檔,接著點選File>PS to EPS
然後就會出現一個對話框,詢問你要不要自動裁切圖檔或是自己設定bounding box
建議是自己設定bounding box,這樣輸出的eps檔就可以直接引入latex中

但是我自己測試的結果,latex compile出來的ps檔看到圖案,不知道是因為我的圖檔太大還是什麼其它的原因,所以只好再找其它的方法

方法二 使用Adobe writer
這個方法其實有點笨,但是轉出來的eps檔latex可以讀,所以不失為一個好方法。
首先開啟Adobe 8 professional,接著匯入剛才儲存的ps檔,匯入之後,adobe會把他轉成PDF檔。
PDF檔!!!沒錯用這個方法就是必須將ps檔轉成pdf檔,然後再轉存eps檔,是不是很麻煩丫。
而且轉出來的eps檔還比較GSview轉出來的還要大。
此外,因為它沒辦法自己設定bounding box,所以,轉出來的eps檔會比較大,而且還有不必要的空白。

方法三 使用Gimp
Gimp是一款open source的繪圖軟體,所以可以把之前jpg、png或是其它的圖檔轉存成eps檔。
這樣就不用把剛才的png檔轉成ps檔啦。有時候用Adobe轉出來不好的檔案,可以用Gimp轉或許有不同的效果。

以上就是我測試過轉eps的三種方法
有了eps檔就可以在latex中插入符合IEEE格式的圖檔啦

首先在latex前文區
要加入
\usepackage{graphicx}

接著在本文中插入圖片
\begin{figure}
\centering
\includegraphics[bb= x1 y1 x2 y2, width=0.3]{XXX.eps}
\caption{This is test!}
\label{fig:test}
\end{figure}

compile完之後就可以在你的pdf檔看到圖檔啦。
延申閱讀:
http://www.math.sinica.edu.tw/www/tex/latex_graphic.jsp
http://aqery.org/blog/?p=241
http://blog.pixnet.net/keejko/post/8686660
http://cbir.spaces.live.com/blog/cns!BA142C20617AEAA1!864.entry
http://philosopherandromeda.wordpress.com/2008/07/13/latex-%E5%8A%9D%E5%AD%A6%E7%AF%87/
Related Posts Plugin for WordPress, Blogger...