instance method
foreign_key
Ruby on Rails 4.0.13
Since v2.2.3Signature
foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
Creates a foreign key name from a class name. separate_class_name_and_id_with_underscore sets whether the method should put ‘_’ between the name and ‘id’.
'Message'.foreign_key # => "message_id" 'Message'.foreign_key(false) # => "messageid" 'Admin::Post'.foreign_key # => "post_id"
Parameters
-
class_namereq -
separate_class_name_and_id_with_underscoreopt = true
Source
# File activesupport/lib/active_support/inflector/methods.rb, line 198
def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
underscore(demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? "_id" : "id")
end
Defined in activesupport/lib/active_support/inflector/methods.rb line 198
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::Inflector