Chen Log

陳洛格

Posts Tagged ‘ror

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

Advertisements

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 , ,

can’t convert Fixnum into String

leave a comment »

スクリーンショット 2013 09 16 20 31 14

 

原本程式,
修改前:

<%= keyin.sale_price.rjust(12,0) %>

 

修改後:
<%= keyin.sale_price.rjust(12,’0′) %>
或是: 
<%= keyin.sale_price.to_s.rjust(12,’0′) %>

 

注意!就是『零』左右兩邊的引號有打錯變成其他字形或是數字無法轉換成字串。

Written by chenagw

2013/09/16 at 20:49

Posted in Uncategorized

Tagged with

如何讓 Ruby on Rails 在Mac開機就啓動

leave a comment »

Screen Shot 2012 10 24 at 16 41 46

每次要在 terminal 打 rails server 指令太麻煩了,
尤其server重開機的時候還要再重打一次,

所以我們就用這個好用的東西:

POW
http://pow.cx

Written by chenagw

2012/10/24 at 16:42

Posted in Uncategorized

Tagged with , , ,

Ruby on Rails 時區 TimeZone 設定

leave a comment »

Ruby on Rails 時區 TimeZone 設定

首先,資料庫裡面的時間一定都是儲存 UTC 時間。
而 Rails 提供的機制是讓你從資料庫拿資料時,
自動幫你轉換時區。例如,要設定台北 +8 時區:

首先設定 config/application.rb

Screen Shot 2012 08 30 at 18 56 34

Screen Shot 2012 08 30 at 18 56 20

中預設時區為

config.time_zone = “Taipei”,

 

如此 ActiveRecord 便會幫你自動轉換時區,
也就是拿出來時 +8,存回去時 -8 。

ps. 改完記得重開Server不然不會有效果

Written by chenagw

2012/08/30 at 18:58

Posted in Uncategorized

Tagged with , , ,