Reputation: 3560
I am getting the following error while trying to split a photo url which is fetched from DB.
Error:
TypeError (wrong argument type Fixnum (expected Regexp)):
Please check my below line of code.
@sdf=TSdf.find_by_Receipt_No(params[:sdf][:Receipt_No])
# output of @sdf.photo=C:\Swargadwara_Puri\SDF\2015-05-03_05-04-07-PM_DECEASED_150503012.jpg
@[email protected]
@b_photos=@b_photo.split(23)
Here i need only @b_photos=2015-05-03_05-04-07-PM_DECEASED_150503012.jpg
Please help me to resolve this error.
Upvotes: 0
Views: 230
Reputation: 121000
String#split
splits the string into array by pattern:
@b_photos = @b_photo.split(File::SEPARATOR).last
Here we split the string into array by File::SEPARATOR
, containing parts of path and choose the very last item, which is apparently the file name.
Whether the path may come from both windows and unix environments, the separator may differ:
@b_photos = @b_photo.split(/[\/\\]/).last
Upvotes: 1