I need something better than split...

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

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]

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

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

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

> > 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"]