zmilojko
zmilojko

Reputation: 2135

Rails 3.1.1 ActiveRecord table_name= doesn't work

I was stuck for quite a while on this:

class Something< ActiveRecord::Base
  table_name= "different_name"
end

and it didn't work, saying table 'Something' does not exist (which is true), until I changed that doomed line to

  set_table_name "different_name"

This would be OK, except that Rails Guide claims that set_table_name is 'Also aliased as: table_name='.

Now, I am new to rails, but what does that 'also aliased' mean? Or is this just a bug?

Upvotes: 2

Views: 2088

Answers (1)

Xavier Shay
Xavier Shay

Reputation: 4127

You need to do self.table_name = "different_name" to use that form. This is a ruby thing: it is assigning a local variable table_name rather than actually calling the method.

Upvotes: 7

Related Questions