undefined method `set_table_name' while migrating (Rails 4) #261

Closed
mcmegavolt opened this Issue Aug 13, 2013 · 8 comments

Comments

Projects
None yet
3 participants

when I run migration I get error:

undefined method `set_table_name' for Article::Category::Translation(Table doesn't exist): Class /home/user/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:22:in `method_missing'

My code:

models/article/category.rb

class Article::Category < ActiveRecord::Base
    translates :name, :description
end

migration file

class TranslateCategories < ActiveRecord::Migration
  def self.up
    Article::Category.create_translation_table!({
      :name => :string,
      :description => :text
    }, {
      :migrate_data => true
    })
  end

  def self.down
    Article::Category.drop_translation_table! :migrate_data => true
  end
end
Owner

parndt commented Aug 13, 2013

Which version of Globalize are you using? Are you using the rails4 branch? In Gemfile:

gem 'globalize3', github: 'svenfuchs/globalize3', branch: 'rails4'

no, I just use

gem 'globalize3'

sory, I have not found gem installing instructions for Rails 4 before :)

When I use your solution, I get error while bundle update

Could not find gem 'paper_trail (~> 3.0.0.beta) ruby', which is required by gem 'globalize3 (>= 0) ruby', in any of the sources.
Contributor

shioyama commented Aug 14, 2013

You have to also use the latest version of paper_trail by explicitly putting it in your gemfile, like this:

gem 'paper_trail', github: 'airblade/paper_trail', branch: 'master'

See the rails4 branch readme.

Thnks, it worked!
One more question, do I need :name and :description fields in original article_categories table?

Contributor

shioyama commented Oct 25, 2013

If you have migrated your data to the translations table, you should no longer need the name and description columns in the original table.

Also FYI, the rails4 branch is now master, and we've created a new globalize gem with major version numbers locked to AR numbers, so you can just use:

gem 'globalize', '~> 4.0.0.alpha.2'

Can I close this?

Yeah, thank you!

Contributor

shioyama commented Oct 25, 2013

Great, thanks!

shioyama closed this Oct 25, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment