Skip to content

Commit

Permalink
Fix problem with migrations template that can cause bogus code to be …
Browse files Browse the repository at this point in the history
…created

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
sabat authored and josevalim committed Jun 20, 2010
1 parent f9abbf9 commit 4515947
Showing 1 changed file with 8 additions and 4 deletions.
@@ -1,11 +1,15 @@
class <%= migration_class_name %> < ActiveRecord::Migration
def self.up<% attributes.each do |attribute| %>

This comment has been minimized.

Copy link
@dewski

dewski Jun 25, 2010

Contributor

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

This comment has been minimized.

Copy link
@josevalim

josevalim Jun 25, 2010

Contributor

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

This comment has been minimized.

Copy link
@lukaszx0

lukaszx0 Jun 25, 2010

Member

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

This comment has been minimized.

Copy link
@josevalim

josevalim Jun 25, 2010

Contributor

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

This comment has been minimized.

Copy link
@lukaszx0

lukaszx0 Jun 25, 2010

Member

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?

This comment has been minimized.

Copy link
@josevalim
<%= 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.