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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
On Fri, Nov 9, 2012 at 3:27 PM, Erwin <yves_dufour-ee4meeAH724@public.gmane.org> 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? ) >I''m not sure if it''s possible to do it in a single line (as far as you want to have a tidy code) opts = { event: :authentication } opts[:subdomain] = subdomain if subdomain sign_me @user, opts> > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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. > > >-- ------------------------------------------------------------- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
thanks Le vendredi 9 novembre 2012 08:27:59 UTC+1, Erwin a écrit :> > 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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/t2EL2hvK22MJ. For more options, visit https://groups.google.com/groups/opt_out.
On 9 November 2012 07:27, Erwin <yves_dufour-ee4meeAH724@public.gmane.org> 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?) ) or sign_me(@user, :event => :authentication, :subdomain => (subdomain unless subdomain.nil?) ) 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Fri, Nov 9, 2012 at 5:25 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 9 November 2012 07:27, Erwin <yves_dufour-ee4meeAH724@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On 9 November 2012 09:37, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On Fri, Nov 9, 2012 at 5:25 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> >> On 9 November 2012 07:27, Erwin <yves_dufour-ee4meeAH724@public.gmane.org> 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>''I am not surprised that did not work, my answer was not intended to convey any suggestion that it would work, just something that would be interesting to try.> >> >> 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 :DYes, it will pass the subdomain as nil, so it depends on the context whether this is satisfactory. Colin> >>> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > To unsubscribe from this group, send email to >> > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
I have a related question. I was suggesting Erwin to use just: sign_me(@user, :event => :authentication #?, :subdomain => subdomain) because if subdomain is nil, sign_me should correctly handle it. I mean, in an hypothetical sign_in method I''d write: def sign_me(user, options) if options[:subdomain] # do_something end end if subdomain is nil the method handles it correctly. but with this code: def sign_me(user, options) if options.has_key? :subdomain # do_something end end this goes wrong ("options.has_key? :subdomain" is true)! So I''d say the first implementation seems more correct, do you agree with me or I'' missing something important about checking hash parameters? -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On 9 November 2012 13:44, Tommaso Visconti <tommaso.visconti-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a related question. > I was suggesting Erwin to use just: > > sign_me(@user, :event => :authentication #?, :subdomain => subdomain) > > because if subdomain is nil, sign_me should correctly handle it. > I mean, in an hypothetical sign_in method I''d write: > > def sign_me(user, options) > if options[:subdomain] > # do_something > end > end > > if subdomain is nil the method handles it correctly.That is the way I would do it. Colin> but with this code: > > def sign_me(user, options) > if options.has_key? :subdomain > # do_something > end > end > > this goes wrong ("options.has_key? :subdomain" is true)! So I''d say the > first implementation seems more correct, do you agree with me or I'' missing > something important about checking hash parameters? > > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Thanks Colin I finally decided to keep the :subdomain option and let the method decide about what to do with it ( seems to be the common pattern) Le vendredi 9 novembre 2012 10:26:34 UTC+1, Colin Law a écrit :> > On 9 November 2012 07:27, Erwin <yves_...-ee4meeAH724@public.gmane.org <javascript:>> 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?) ) > or > sign_me(@user, :event => :authentication, :subdomain => > (subdomain unless subdomain.nil?) ) > > 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 rubyonra...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<javascript:>. > > > To unsubscribe from this group, send email to > > rubyonrails-ta...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>. > > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/vXU0ybxpA5EJ. For more options, visit https://groups.google.com/groups/opt_out.
Seemingly Similar Threads
- <form> tag is self-closing before input fields .. (HAML generator used)
- Advice needed --- Best way to get mysql2 gem installed to interact with Mysql Database?
- Need some guidance on running shell commands from my app..
- [Rails 3.2] form_tag w :remote => true doesn't fire up the js format
- How to bypass a create record after validation wo error ?