Forum: Ruby on Rails backup (*~) view files are being used instead of proper view

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
73c04e9ef9ca435c5b19a2e765ae6d20?d=identicon&s=25 Max Williams (max-williams)
on 2009-04-21 15:58
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
73c04e9ef9ca435c5b19a2e765ae6d20?d=identicon&s=25 Max Williams (max-williams)
on 2009-04-22 11:11
SOLVED - I upgraded to rails 2.3.2 (this problem was happening for me in
2.3.0) and the problem went away.  It was definitely a problem with
rails because i made a new app and it had the same problem, which also
went away when i upgraded rails.

So, it seems that rails 2.3.0 prefers view files ending in '.html.erb~'
to ones that end in 'html.erb'.  Something to watch out for.  I'm still
curious as to why it was doing that, if anyone knows, and how to tell it
not to (in case it starts happening again).
054ea2f04b5592b91f8223796cc53979?d=identicon&s=25 Brendon Whateley (brendon)
on 2009-04-23 02:39
(Received via mailing list)
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

On Apr 22, 2:11 am, Max Williams <rails-mailing-l...@andreas-s.net>
73c04e9ef9ca435c5b19a2e765ae6d20?d=identicon&s=25 Max Williams (max-williams)
on 2009-04-23 09:22
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)
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-04-23 10:09
(Received via mailing list)
On Apr 23, 8:22 am, Max Williams <rails-mailing-l...@andreas-s.net>
wrote:
> 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
73c04e9ef9ca435c5b19a2e765ae6d20?d=identicon&s=25 Max Williams (max-williams)
on 2009-04-23 10:33
Hi Frederick

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

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).
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2009-04-23 10:56
(Received via mailing list)
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.

2009/4/23 Max Williams <rails-mailing-list@andreas-s.net>
73c04e9ef9ca435c5b19a2e765ae6d20?d=identicon&s=25 Max Williams (max-williams)
on 2009-04-23 11:21
Colin Law wrote:
> 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.
>
> 2009/4/23 Max Williams <rails-mailing-list@andreas-s.net>

Yeah, tbh i think you're probably right.  I should just tell gedit to
stop making backups, i very *very* rarely ever use them.  I already had
to tell git to ignore them and occasionally one manages to slip through
anyway, not great.
054ea2f04b5592b91f8223796cc53979?d=identicon&s=25 Brendon Whateley (brendon)
on 2009-04-23 21:53
(Received via mailing list)
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...
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2009-04-23 22:11
(Received via mailing list)
2009/4/23 Brendon <brendon@darkindigo.com>

> 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.
This topic is locked and can not be replied to.