With params[:action] = "edit_facilities", this works... params[:action].split(''_'')[1] but not with params[:action] = "edit_board_volunteer" because it splits at each underscore How can I get everything after the first underscore character? Craig --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Craig White wrote:> With params[:action] = "edit_facilities", this works... > > params[:action].split(''_'')[1] > > but not with params[:action] = "edit_board_volunteer" because it splits > at each underscore > > How can I get everything after the first underscore character? > > CraigHi Craig, You can try a = params[:action] a.split(''_'')[1..a.length] When I try that with ''edit_board_volunteer'', I get>> s = ''edit_board_volunteer''=> "edit_board_volunteer">> s.split(''_'')[1..s.length]=> ["board", "volunteer"] Peace, Phillip -- Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 31 May 2008, at 18:25, Phillip Koebbe wrote:> > Craig White wrote: >> With params[:action] = "edit_facilities", this works... >> >> params[:action].split(''_'')[1] >> >> but not with params[:action] = "edit_board_volunteer" because it >> splits >> at each underscore >> >> How can I get everything after the first underscore character? >> >> Craig > > Hi Craig, > > You can try > > a = params[:action] > a.split(''_'')[1..a.length] >or a.match(/[^_]*_(.*)/)[1] Fred> When I try that with ''edit_board_volunteer'', I get > >>> s = ''edit_board_volunteer'' > => "edit_board_volunteer" >>> s.split(''_'')[1..s.length] > => ["board", "volunteer"] > > Peace, > Phillip > -- > Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sat, 31 May 2008 10:02:17 -0700 Craig White <craigwhite-BQ75lA0ptkhBDgjK7y7TUQ@public.gmane.org> wrote:> > With params[:action] = "edit_facilities", this works... > > params[:action].split(''_'')[1] > > but not with params[:action] = "edit_board_volunteer" because it splits > at each underscore > > How can I get everything after the first underscore character? > > Craig >params[:action].split(''_'',2) Splits into at most two array entries.>> "edit_board_volunteer".split(''_'',2)=> ["edit", "board_volunteer"] Regard, Jon --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sat, 2008-05-31 at 19:52 +0100, Jonathan Stott wrote:> On Sat, 31 May 2008 10:02:17 -0700 > Craig White <craigwhite-BQ75lA0ptkhBDgjK7y7TUQ@public.gmane.org> wrote: > > > > > With params[:action] = "edit_facilities", this works... > > > > params[:action].split(''_'')[1] > > > > but not with params[:action] = "edit_board_volunteer" because it splits > > at each underscore > > > > How can I get everything after the first underscore character? > > > > Craig > > > > params[:action].split(''_'',2) > > Splits into at most two array entries. > > >> "edit_board_volunteer".split(''_'',2) > => ["edit", "board_volunteer"]---- bing! much nicer/prettier than (params[:action].split(''_'')[2] == nil ? params[:action].split(''_'')[1] : params[:action].split(''_'')[1] + "_" + params[:action].split(''_'')[2]) Thanks Craig --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---