0

有没有办法有条件地为方法设置选项?

就像是...

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

所以在那种情况下......只有host在用户为其帐户设置了某个选项时才设置。

4

1 回答 1

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

或者一个班轮:

article_url @article, @user.custom_domain? ? {:host => 'myblog.com'} : {}
于 2012-06-08T12:39:58.173 回答