0

Is there a way to conditionally set options for a method?

Something like...

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

So in that case...only setting host if the user has a certain option set for their account.

Shpigford
  • 24,748
  • 58
  • 163
  • 252

1 Answers1

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

Or a one liner:

article_url @article, @user.custom_domain? ? {:host => 'myblog.com'} : {}
Agis
  • 32,639
  • 3
  • 73
  • 81
Mori
  • 27,279
  • 10
  • 68
  • 73