rails console: find all columns of a model

Lets assume we have Branch table
Branch.column_names.join(" ")


Rails: add foreign key to existing column with different column names

Reference migration

class CreateBranches < ActiveRecord::Migration[5.1]
  def change
    create_table :branches do |t|
      t.string :name
      t.string :email
      t.string :phone
      t.string :alternate_phone
      t.string :mobile
      t.integer :contact_one_id, index: true #add columns as integer
      t.integer :contact_two_id, index: true #add columns as integer
      t.references :address, foreign_key: true

    #add foreign key constraints on columns
    add_foreign_key :branches, :employees, column: :contact_one_id
    add_foreign_key :branches, :employees, column: :contact_two_id

and put belongs_to relation in Branch model

class Branch < ApplicationRecord
  belongs_to :contact_one, class_name: 'Employee'
  belongs_to :contact_two, class_name: 'Employee'

How to succeed as a software engineer?

I was searching for this answer and after reading much articles, I found this note on quora.

  • Make Computer Science fundamentals very strong , mainly DataStructure & Algorithm.
  • Make a habit of solving at least 3-4 code snippets/Week , check Leetcode/CareerCup
  • No point of being a master of single technology like Java or Python. Learn several technologies. It will broaden your skill-sets & thinking. And now you are already ahead in the race of Developers and Interviews.
  • Heard any new technology, like BigData or Machine Learning. Make sure to understand that and implement a POC. Don’t just read, make sure, you are very much aware of fundamentals. Like you must know the architecture, go through the case studies and BUILD SOMETHING.
  • You gotta market yourself. If you are learning from open Source, its your responsibility, to give back something. Make your github account and contribute. This will make your profile very shiny.
  • Don’t fall in love with any single technology. I saw Desktop based application lost its place and now Mobile is rocking, and I wont be amaze if Virtual Reality takes its place or something. So stop falling in love with any technology. Learn whatever is good in market. Yeah it will be huge but your habit will make you proficient to learn anything new and You will be truly a Quick learner.
  • Attend Hackathons and Technical Meetup. Even you don’t know anything, doesn’t matter. You must build contacts. the more people you know, the probability to end up with better jobs will be more higher.
  • If you don’t like your job or Manager don’t react, keep smiling and keep working and look for new job. Never destroy your relationship with people.
  • Read .. Read … Read … CODE IT

Happy learning