Reputation: 8487
I'm working with a set of files in a Rails project and I need to get the current file name. I'm using the following:
<%= __FILE__ %>
But it is outputting the full file path:
/Users/[myuser]/Documents/Development/welcome.html.erb
I just need the file name:
welcome
How can I do this?
Upvotes: 0
Views: 2287
Reputation: 34318
To get the filename only, you can use File#basename method:
File.basename(__FILE__, '.html.erb')
# => welcome
or,
File.basename(__FILE__, '.*')
# => welcome
So, your code becomes:
<%= File.basename(__FILE__, '.html.erb') %>
Upvotes: 2