Chen Log

陳洛格

Posts Tagged ‘rails

AutoLink on ruby on rails

leave a comment »

Because the AutoLink on rails has removed in rails 3.1,

so if you have to use the function you must be install other gem: 「Rinku

 

Before you start to install the Rinku Gem,

you must install the Xcode app and agree the license.

then 

$ gem install rinku

 

  • Inserted require 'rinku' into the controller file
  • Inserted the following into the view file <% text = "Go to http://www.abc.com or email me at dude@abc.com" %> and <%= Rinku.auto_link(text, mode=:all, link_attr=nil, skip_tags=nil) %>

key those text on the view file:

auto_link('http://www.pokemon.com', :all, 'target="_blank"')

Reference this url:
https://github.com/vmg/rinku 
http://stackoverflow.com/questions/6418710/replacing-the-auto-link-method-in-ruby-on-rails-3-1

Written by chenagw

2014/04/21 at 00:40

Posted in Uncategorized

Tagged with , , ,

Pow port forward 設定使用方式

leave a comment »

讓 pow 的網址改連到 rails s 打開的 server

如此一來就可以披著 xxx.dev 的網址,實際上連到 rails s -p 3000 (或其他 port) 開好的 server。

參考 pow manual – 2.1.4 Port Proxying

  1. cd ~/.pow/
  2. rm project_name 把你原本的 link 移掉
  3. echo 13001 > project_name 把想用的 port 寫到原名的檔案裡
  4. cd 到你的 project 目錄
  5. rails s -p 13001 ﹣d

加上 -d 是讓程式可以在背景執行 不用一直開著終端機的視窗

需注意如果你有多個 projects,必須自己管理網址跟 port 的對應。

 

詳情請參考:

http://ascendbruce.logdown.com/posts/206764-extend-pow-kill-idle-timeout-and-pow-working-with-spring-or-zeus

Written by chenagw

2014/04/03 at 01:12

Posted in Uncategorized

Tagged with , , , ,

視覺化管理 POW 的軟體-Anvil For Mac

leave a comment »

螢幕快照 2014 04 03 00 29 31

Zero-config through Pow

http://anvilformac.com/

 

Written by chenagw

2014/04/03 at 00:31

Posted in Uncategorized

Tagged with , ,

Rails ruby資料形態

leave a comment »

Here are all the Rails3 (ActiveRecord migration) datatypes:

:binary
:boolean
:date
:datetime
:decimal
:float
:integer
:primary_key
:references
:string
:text
:time
:timestamp

Source:http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html#method-i-column

Written by chenagw

2014/02/25 at 13:30

Posted in Uncategorized

Tagged with , ,

去掉 Float 浮點數字 後面的 0

leave a comment »

如何把 55.0 變成 55?
這是ruby浮點運算常需要遇到的問題。
 

float.to_s.gsub(/(\.?0+$)/,””).gsub(/(\.+)/,”.”)

直接把浮動數字後面多餘的零去掉!

參考網頁:

http://railsforum.com/viewtopic.php?id=24996

Written by chenagw

2013/01/19 at 00:47

Posted in Uncategorized

Tagged with ,

Ruby on Rails 字串連接方法

leave a comment »

PHP的連接是用點 “ . ”  如這樣:

$a=”500″;
$b=”apple”;

echo $a.$b;

// print: ” 500apple” 

而Java的話是採用 “+” 加號。

Ruby String字串與Value變數的的連接長的比較變態一點,
是這樣的:

$str = "#{@str1}ABCD#{@str2}CFDE"

 

沒錯!
就是引號內加上#{@變數} = “#{@變數} “

Written by chenagw

2013/01/11 at 13:46