Q:

Rails 4 - How can I map 2 columns of a Model to another column of another model

I want to map 2 columns of the same model (dev_status and test_planning_status) to another model's column (Status.name) and in the UserStory form I want to have a dropdown with values from Status table
I have tried something like this but unable to figure out 
Status model is like this 
class Status < ActiveRecord::Base
  has_many :dev_status, :class_name => 'UserStory', :foreign_key => 'dev_status_id'
  has_many :test_planning_status, :class_name => 'UserStory', :foreign_key => 'test_planning_status_id'
end

Currently I have this in models/UserStory
class UserStory < ActiveRecord::Base
validates :us_number, presence: true
validates :team_id, presence: true
validates :dev_status,  presence:true
validates :test_status,  presence:true
belongs_to :team

CreateUserStories migration is 
class CreateUserStories < ActiveRecord::Migration
   def change
     create_table :user_stories do |t|
     t.string :us_number
     t.references :team
     t.string :dev_status
     t.string :test_planning_status
     t.integer :tc_count
     t.timestamps null: false
  end
  add_foreign_key :user_stories, :pod
end

My UserStoryController params is 
def user_story_params
  params.require(:user_story).permit(:us_number, :team_id, :dev_status, :test_planning_status)
end

UserStory _form is 
<%= f.label :dev_status,'Dev Status' %>
    <%= f.select :status, Status.all.map {|u|[u.status, u.id]}, 
                                      {include_blank: true} %>

<%= f.label :test_planning_status, 'Test Planning Status' %>
    <%= f.select :status, Status.all.map {|u|[u.status, u.id]}, 
                                      {include_blank: true} %>

A:

The goal should be to call UserStory.dev_status.name to get the dev_status name, and UserStory.test_planning_status.name to get the test_planning_status name.

Your migration should be creating columns dev_status_id (not dev_status) and test_planning_status_id (not test_planning_status). 
Use t.references or t.belongs_to in your future migrations.
Above columns should be integers, not strings.
You need to specify belongs_to on the UserStory object for your status fields.
belongs_to :dev_status, class_name: 'Status'
belongs_to :test_planning_status, class_name: 'Status'

Change 
validates :test_status, presence:true
to
validates :test_planning_status, presence:true
The two f.select :status in your form need to be changed to f.select :test_planning_status and f.select :dev_status

That should get you pointed in the right direction. Hope it helps!

