2012-06-08 40 views
0

有沒有一種方法來有條件地設置方法的選項?有條件地設置方法選項?

喜歡的東西...

article_url(@article, :host => 'myblog.com' if @user.custom_domain?) 

因此,在這種情況下...只有設置host如果用戶有一定的選擇爲他們的帳戶設置。

回答

4
opts = @user.custom_domain? ? {:host => 'myblog.com'} : {} 
article_url @article, opts 

或者一個襯墊:

article_url @article, @user.custom_domain? ? {:host => 'myblog.com'} : {} 
+0

也許你應該考慮提取到一個幫手這個呢。 – Agis