Permalink
Browse files

Fix problem with migrations template that can cause bogus code to be …

…created

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent f9abbf9 commit 451594784552bd6955687d8ff617c484ec26946b @sabat sabat committed with josevalim Jun 11, 2010
View
12 activerecord/lib/rails/generators/active_record/migration/templates/migration.rb
@@ -1,11 +1,15 @@
class <%= migration_class_name %> < ActiveRecord::Migration
def self.up<% attributes.each do |attribute| %>
@dewski
dewski added a line comment Jun 25, 2010

When creating a migration, now it shows up with no new line but instead just def self.up end rather than def self.up\n like so: https://gist.github.com/33a65ec8e77eeac4a5eb

@josevalim
Ruby on Rails member
josevalim added a line comment Jun 25, 2010

Patch please? You can assign it direct to me! Thanks!

@lukaszx0
Ruby on Rails member
lukaszx0 added a line comment Jun 25, 2010

It's small one, so I think there is no reason to create a ticket. Here you have the patch: http://gist.github.com/452574

@josevalim
Ruby on Rails member
josevalim added a line comment Jun 25, 2010

Thanks for the patch, but now it's leaving extra lines. :( I guess the proper fix is to use <%- if %> <% end -%> instead of <%- if -%>.

Another solution, based on 2-3 behavior, is to clean up the attributes hash if no migration_action is given and then:

http://github.com/rails/rails/blob/2-3-stable/railties/lib/rails_generator/generators/components/migration/templates/migration.rb

@lukaszx0
Ruby on Rails member
lukaszx0 added a line comment Jun 25, 2010

Hmm, I've checked that, and it was leaving extra spaces/tabs not extra lines. I've updated gitst, tested it and it work fine for me: http://gist.github.com/452574

It generates migrations like this: http://gist.github.com/452617 and this is what we want to achieve, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
- <%= migration_action %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'add' %>, :<%= attribute.type %><% end -%>
- <%- end %>
+ <%- if migration_action -%>
+ <%= migration_action %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'add' %>, :<%= attribute.type %><% end %>
+ <%- end -%>
+ <%- end -%>
end
def self.down<% attributes.reverse.each do |attribute| %>
- <%= migration_action == 'add' ? 'remove' : 'add' %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'remove' %>, :<%= attribute.type %><% end -%>
- <%- end %>
+ <%- if migration_action -%>
+ <%= migration_action == 'add' ? 'remove' : 'add' %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'remove' %>, :<%= attribute.type %><% end %>
+ <%- end -%>
+ <%- end -%>
end
end

0 comments on commit 4515947

Please sign in to comment.