On Fri, Nov 9, 2012 at 5:25 PM, Colin Law <[email protected]> wrote:

> On 9 November 2012 07:27, Erwin <[email protected]> wrote:
> > When I have this pattern
> >
> >        sign_me(@user, :event => :authentication, :subdomain => subdomain)
> >
> > how can I write it to avoid sending the :subdomain option if
> subdomain.nil?
> > ( if possible ..)
> >
> >        sign_me(@user, :event => :authentication  #?, :subdomain =>
> subdomain
> > unless subdomain.nil?  )
>
> You could try
>         sign_me(@user, :event => :authentication, (:subdomain =>
> subdomain unless subdomain.nil?)  )
>

I was surprised that you answered this Colin so I tried it out but I got a
syntax error

>> app.root_path(foo: 'me', (bar: 'blah' if false))
SyntaxError: (irb):17: syntax error, unexpected tLABEL
app.root_path(foo: 'me', (bar: 'blah' if false))
                              ^
(irb):17: syntax error, unexpected ')', expecting tASSOC
from
/home/jim/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.2/lib/rails/commands/console.rb:47:in
`start'
from
/home/jim/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.2/lib/rails/commands/console.rb:8:in
`start'
from
/home/jim/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.2/lib/rails/commands.rb:41:in
`<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'


> or
>         sign_me(@user, :event => :authentication, :subdomain =>
> (subdomain unless subdomain.nil?)  )
>

and this still passes subdomain as a key if used in a hash but if used in a
routes helper, this will work :D

>> app.root_path(foo: 'me', bar: ('blah' if false))
=> "/?foo=me"


> Colin
>
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Ruby on Rails: Talk" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > To view this discussion on the web visit
> > https://groups.google.com/d/msg/rubyonrails-talk/-/TOTAudTTAa8J.
> > For more options, visit https://groups.google.com/groups/opt_out.
> >
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>


-- 
-------------------------------------------------------------
visit my blog at http://jimlabs.heroku.com

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to