His example was written last July, and uses Rails 3.0.0 beta 4. An updated version was completed by Jacob Poulsgaard Tjoernholm, and works in Rails 3.0.3; it even works after a bump to 3.0.5. The problem is that it doesn't work in my project. Why? Because the rails method
class_name
was removed from the release candidate of Rails 3. The method class_name
translates a table name into a class name. This can also be accomplished with the .singularize.camelize.constantize
string of methods. .class_name
was used in two separate spots, in the import tables controller
, and in the show page of import_tables
. In the import tables controller
, I used ActiveRecord::Base.connection.tables.select { |t| t == merge_table }
to return tables that match merge_table
, then .first
to select the only element in the resulting array. Finally I used .singularize.camelize.constantize
again to turn it into a class name.The second place to avoid using
class_name
is in the import_tables/show
view. There you can change ActiveRecord::Base.const_get(ActiveRecord::Base.class_name(table)).columns
into table.singularize.camelize.constantize.columns
. Again it takes the table name and changes it into a class name, using some rails inflectors.
No comments:
Post a Comment