Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails destroy command concatenates first/last lines of config/routes.rb #15913

Closed
ethagnawl opened this issue Jun 25, 2014 · 3 comments
Closed
Assignees
Labels

Comments

@ethagnawl
Copy link

In Rails 4.1.1, when only one resource (foo) has been created and all lines that are empty or contain only comments have been removed from routes.rb, running rails destroy scaffold foo will concatenate the first and last lines of routes.rb and result in a NameError.

Rails.application.routes.draw doend

This gist can be used to reproduce the bug.

@tohyongcheng
Copy link

I reproduced the same error on Rails 4.1.1 and Rails 4.1.2 when following your gist.

For Mac OS, you need to change the sed commands to prevent the error 'sed: -i may not be used with stdin' . The gist to reproduce the bug on a Mac machine is here.

Possibly, we can just ensure a line break before the end after each destroy command in the routes.rb

@akolomiychuk
Copy link
Contributor

I found that a problem is not in rails itself, but in thor gem.

This is corresponding code line in rails: https://github.com/rails/rails/blob/master/railties/lib/rails/generators/actions.rb#L97

@ethagnawl ethagnawl changed the title Rails destroy command concatenates first/last lines of config.rb Rails destroy command concatenates first/last lines of config\/routes.rb Nov 11, 2014
@ethagnawl ethagnawl changed the title Rails destroy command concatenates first/last lines of config\/routes.rb Rails destroy command concatenates first/last lines of config/routes.rb Nov 11, 2014
@ethagnawl
Copy link
Author

This issue also applies to Rails 4.2.0.

@pixeltrix pixeltrix self-assigned this Feb 2, 2015
pixeltrix added a commit that referenced this issue Feb 3, 2015
When there is a single scaffold in the routes.rb with no other lines
then revoking/destroying it will create a routes.rb file with a syntax
error. This is because the sentinel for the Thor `route` action didn't
include the newline but the logged route code did.

The fix is to add the newline to the sentinel and remove it from the
the logged route code.

Fixes #15913.

Conflicts:
	railties/CHANGELOG.md
pixeltrix added a commit that referenced this issue Feb 5, 2015
When there is a single scaffold in the routes.rb with no other lines
then revoking/destroying it will create a routes.rb file with a syntax
error. This is because the sentinel for the Thor `route` action didn't
include the newline but the logged route code did.

The fix is to add the newline to the sentinel and remove it from the
the logged route code.

Fixes #15913.

(cherry picked from commit 1c59ffc)

Conflicts:
	railties/CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants