Rails is unable to load a partial that has only numbers (or if numbers lead before alphabetical characters), and I'm not sure if it's an error on my part, or just an expected behavior of render.
I have:
<%= render "pages/announcements/#{params[:date]}" rescue render 'pages/announcements/none' %>
and two partials:
pages/announcements/_none.html.erb
pages/announcements/_2014_09_01.html.erb
The numerical file name is always ignored, and the 'none' partial is loaded.
When I change this to have a leading alphabetical character, all is fixed:
<%= render "pages/announcements/news_#{params[:date]}" rescue render 'pages/announcements/none' %>
with:
pages/announcements/_none.html.erb
pages/announcements/_news_2014_09_01.html.erb
Can someone explain this behavior or my error?
If you remove the rescue you'll probably get a more helpful error message:
Gives:
This seems to be because ActionView internally converts the partial name into a symbol.
(I bumped into this recently. Putting a prefix on the partial name wasn't a huge imposition in my case, hopefully the same is true of yours.)