Search code examples
ruby-on-rails-5rubymine

Completing attribute name in RubyMine?


I'm trying Rails in RubyMine 2016.2.4. How to use the code completion for model's attribute name? In Yii2 the model's attributes are listed in comments


Solution

  • Internal structure and philosophy of Rails are different than Yii2's. Current database state is stored in separate special file called db/schema.rb. This file is automatically updated every time after applying new migrations and not intended for manual editing. In Yii2 you need to synchronize PHPDoc comments with current DB state manually. From the other side in Rails you can't see which attributes model contains just by looking at the model (the model code is very laconic in terms of that though).

    Not sure, but I think for model attributes autocomplete RubyMine extracts column names from according table from that file. Read more info about db/schema.rb in official docs.

    Also there is dedicated help section in RubyMine docs about Rails-Aware Code Completion.

    So it works, but probably in specific places.

    And last but not least check this related SO question. RubyMine provides very good autocomplete options, but don't hesitate to peek at db/schema.rb if needed or use DB managing tools to see column names and data during development.