w10schools
Login Register
  • Home
  • Tutorials
    • HTML, CSS
      • HTML, HTML5
      • CSS, CSS3
    • XML
    • JavaScript, AJAX
    • PHP
    • Ruby on Rails
      • Ruby
      • Rails
    • ASP.NET
      • ASP
      • C# .NET
    • Java
      • JSP
    • Databases
      • MySQL
      • MSSQL Server
      • Oracle
    • Web Server
      • Windows
      • Linux
      • Apache
      • IIS
    • Design
      • Dreamweaver
      • Flash
      • Photoshop
      • Fireworks
      • CorelDRAW
      • Illustrator
  • References
    • HTML
      • Bootstrap
    • CSS
      • CSS Selectors
      • Sass
    • JavaScript
    • Mobile Apps
      • Cordova
    • Ruby on Rails
      • Ruby
      • Rails
    • PHP
      • Function
      • Language
      • CodeIgniter
      • Phalcon
      • PHPUnit
      • Symfony
      • Drupal
      • Yii
      • Laravel
    • Perl
      • Perl
    • Python
      • Python
      • Django
      • NumPy
      • Pandas
      • scikit-image
      • scikit-learn
      • Statsmodels
      • Matplotlib
    • Lua
      • Lua
    • C, C++
      • C
      • C++
    • Server
      • Docker
      • Apache HTTP Server
      • Nginx
    • Database
      • PostgreSQL
    • Big Data
      • TensorFlow
    • Game Development
      • Phaser
      • LÖVE
  • Articles
    • News
    • General
      • Website Promotion
      • Online Advertising
      • Make Money Online
    • Editorials
    • Interviews
    • Web Roundups
  • Resources
    • Design
      • Fonts
      • Graphics
      • Vectors
      • Templates
      • UI (User Interface)
      • Brushes
      • Patterns, Backgrounds
      • Textures
    • Web Development
      • HTML, CSS
      • XML
      • JavaScript, AJAX
      • Ruby on Rails
      • PHP
      • Java
      • .NET
      • Python
      • Perl
      • Flash
    • Mobile Application Development
      • Mobile Development Tools
      • Swift
    • Online Services
      • Online Storage
      • Web Hosting
  • Tools
    • Generators
Edit
In Place Editing Advanced Editing
  • References
  • Ruby on Rails
  • Rails
  • Classes
  • ActiveModel
  • ActiveModel::Conversion

to_key

to_key()
Instance Public methods

Returns an Enumerable of all key attributes if any is set, regardless if the object is persisted or not. Returns nil if there are no key attributes.

class Person < ActiveRecord::Base
end

person = Person.create
person.to_key # => [1]
Links:
  • https://github.com/rails/rails/blob/7d196cf360321466c0eefc474bfad1be7e3ea7ab/activemodel/lib/active_model/conversion.rb#L51
doc_ruby_on_rails
doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.

Popular Articles
to_key to_key() Instance Public methods Returns this record's primary key value wrapped in an Array if one is available.
to_key to_key() Instance Public methods
test_to_key test_to_key() Instance Public methods Responds to to_key Returns an Enumerable of all (primary) key attributes or nil if model.persisted
functools.cmp_to_key() functools.cmp_to_key(func) Transform an old-style comparison function to a key function. Used with tools that accept key functions (such as sorted
Key#Key new Key(game, keycode) If you need more fine-grained control over the handling of specific keys you can create and use Phaser.Key objects. Paramet


Return to View
  • Facebook
  • Tweet
  • Digg it
  • Stumbleupon
  • Delicious
  • Plus Share

Designed by : w10schools

service@w10schools.com

Our Partners: aeeble – Providing content publishing and search solutions