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
  • 23,791
  • 55
  • 152
  • 243

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
  • 30,959
  • 2
  • 71
  • 80
Mori
  • 26,205
  • 10
  • 63
  • 70