backup (*~) view files are being used instead of proper view

This is a weird one. I just started making a new app, and have noticed a weird problem: I do my editing in gedit in linux, which saves backup files as '<filename>~', eg "index.html.erb~" for a view template.

I'm running mongrel, and when i refresh a page it's loading the backup view file in preference to the 'proper' file! If there's no backup then it loads the proper file. I can't work out why it's doing this - does anyone have any ideas?

thanks max

It's related to how Rails is compiling templates. It *more or less* ignores the extensions and compiles all the files in all directories under the app/view. It can also bite you if you rename a file to move it out to keep an original version while trying something or if you have a straight html version of the file. I'd suggest that you make sure you don't leave more than one view file with the same base name. (i.e. if you try a haml version, rename the html.erb version.) Remember this if you see a problem... else you would have to fix it by overriding some core rails template code, which is a step on the road to hurt!

Brendon

HI brendon, thanks for answering.

I never saw this before v2.3.0 and it's gone now that i upgraded again to 2.3.2. Your answer suggests that it's a natural behaviour of rails that one has to bear in mind, i'd disagree, it seems like a flat out bug. In order to 'cure' it without upgrading i'd have to use a different text editor, or set it to not make backups. This isn't really acceptable to me. I'm not an authority on rails though, i'd be interested to know what others think. Is it a bug? or should i just keep backup files out of my view folders? (in the hypothetical situation where i was forced to use v2.3.0)

HI brendon, thanks for answering. I'm not an authority on rails though, i'd be interested to know what others think. Is it a bug? or should i just keep backup files out of my view folders? (in the hypothetical situation where i was forced to use v2.3.0)

2.3.0 was a release candidate - if you're forced to use it something is screwed up.

Fred

Hi Frederick

I'm not forced to use it at all, i already said i upgraded to 2.3.2. :slight_smile:

I was just wondering about the hypothetical situation (in some parallel world) where i'm stuck using it and can't just run away from this problem (like i did do by upgrading).

I may be talking rubbish here but I think when using a framework such as Rails it might be considered bad practice to save backups in the project directory structure. In Rails the presence of a file is meaningful. For example it is not necessary to declare that a controller exists, if it is present in the controllers directory then that controller exists. As a general principle then it could be argued that superfluous files should not be saved in the project, just in case.

In addition many would argue that a version control system such as git should be used, with commits to the local repository at every opportunity, and therefore backups are not necessary at all.

I'd say that is rubbish, since many editors create backup files, swap files and other junk following some pretty well defined conventions. Rails template compile code is very greedy and doesn't care much about extensions, even extensions it doesn't understand. That is the bug. Rails should not be the first application to completely ignore file extensions and equate foo.html, foo.txt, foo.backup, foo.html.erb, foo.rjs, foo.haml, foo.rhtml and foo.moved_out_the_way.html.erb as all being equivalent...

As a general principle, source control systems ignore these files and so should rails. You are proposing that anything in the file tree is 100% fair game for Rails which would require many normal development activities to be modified in inconvenient ways...

I’d say that is rubbish, since many editors create backup files, swap

files and other junk following some pretty well defined conventions.

Rails template compile code is very greedy and doesn’t care much about

extensions, even extensions it doesn’t understand. That is the bug.

Rails should not be the first application to completely ignore file

extensions and equate foo.html, foo.txt, foo.backup, foo.html.erb,

foo.rjs, foo.haml, foo.rhtml and foo.moved_out_the_way.html.erb as all

being equivalent…

As a general principle, source control systems ignore these files and

so should rails. You are proposing that anything in the file tree is

100% fair game for Rails which would require many normal development

activities to be modified in inconvenient ways…

I was not suggesting that this is not a deficiency in Rails (I leave that discussion to others). I was suggesting that by not saving extraneous files in the project then the issue could be avoided. That is not rubbish, it is defensive programming.