{"action":"created","issue":{"url":"https://api.github.com/repos/ga-wdi-boston/capstone-project/issues/99","repository_url":"https://api.github.com/repos/ga-wdi-boston/capstone-project","labels_url":"https://api.github.com/repos/ga-wdi-boston/capstone-project/issues/99/labels{/name}","comments_url":"https://api.github.com/repos/ga-wdi-boston/capstone-project/issues/99/comments","events_url":"https://api.github.com/repos/ga-wdi-boston/capstone-project/issues/99/events","html_url":"https://github.com/ga-wdi-boston/capstone-project/issues/99","id":145808321,"number":99,"title":"Create new Player in Rails, not working","user":{"login":"seatuna","id":16471076,"avatar_url":"https://avatars.githubusercontent.com/u/16471076?v=3","gravatar_id":"","url":"https://api.github.com/users/seatuna","html_url":"https://github.com/seatuna","followers_url":"https://api.github.com/users/seatuna/followers","following_url":"https://api.github.com/users/seatuna/following{/other_user}","gists_url":"https://api.github.com/users/seatuna/gists{/gist_id}","starred_url":"https://api.github.com/users/seatuna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/seatuna/subscriptions","organizations_url":"https://api.github.com/users/seatuna/orgs","repos_url":"https://api.github.com/users/seatuna/repos","events_url":"https://api.github.com/users/seatuna/events{/privacy}","received_events_url":"https://api.github.com/users/seatuna/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":20,"created_at":"2016-04-04T21:21:11Z","updated_at":"2016-04-05T19:55:23Z","closed_at":"2016-04-05T19:55:23Z","body":"I have 2 join tables (joins Player and Character, one join table is play_as_character, other is play_against_character) which allows me to access player.characters and player.opponents\r\n\r\n[More context in previous issue](https://github.com/ga-wdi-boston/capstone-project/issues/90)\r\n\r\nPlayer has name and rank.  I want to be able to create player by entering name, rank, characters, and opponents, but I think it's not working since I don't actually have columns named characters or opponents since it's covered by join tables.\r\n\r\n\r\n\r\n```\r\ncurl --include --request POST http://localhost:3000/players \\\r\n  --header \"Authorization: Token token=BAhJIiU5MjVjZTIyOWQ2ZWI5NGI2ZGM0YjEwYjg1ZTM4NzVjZQY6BkVG--276029c8095ad2312d24cb601a0cf0be55ac11d5\" \\\r\n  --header \"Content-Type: application/json\" \\\r\n  --data '{\r\n    \"player\": {\r\n      \"name\": \"seatuna\",\r\n      \"rank\": \"bronze\",\r\n      \"characters\": 3, // I've also tried directly entering characters' names, didn't work\r\n      \"opponents\": 1\r\n    }\r\n  }'\r\n```\r\n\r\nError\r\n```\r\nStarted POST \"/players\" for ::1 at 2016-04-04 16:59:27 -0400\r\nProcessing by PlayersController#create as */*\r\n  Parameters: {\"player\"=>{\"name\"=>\"seatuna\", \"rank\"=>\"bronze\", \"characters\"=>3, \"opponents\"=>1}}\r\n  User Load (0.2ms)  SELECT  \"users\".* FROM \"users\" WHERE \"users\".\"token\" = $1 LIMIT 1  [[\"token\", \"925ce229d6eb94b6dc4b10b85e3875ce\"]]\r\nCompleted 500 Internal Server Error in 59ms (ActiveRecord: 2.9ms)\r\n\r\nNoMethodError (undefined method `each' for 3:Fixnum):\r\n  app/controllers/players_controller.rb:22:in `create'\r\n\r\n\r\n  Rendered /usr/local/var/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_source.erb (5.9ms)\r\n  Rendered /usr/local/var/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.8ms)\r\n  Rendered /usr/local/var/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.6ms)\r\n  Rendered /usr/local/var/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (297.3ms)\r\n```\r\n\r\nPlayer schema\r\n```ruby\r\n  create_table \"players\", force: :cascade do |t|\r\n    t.string   \"name\"\r\n    t.string   \"rank\"\r\n    t.datetime \"created_at\", null: false\r\n    t.datetime \"updated_at\", null: false\r\n    t.integer  \"user_id\"\r\n  end\r\n```\r\n\r\nPlayer model\r\n```ruby\r\nclass Player < ActiveRecord::Base\r\n  belongs_to :user, inverse_of: :users\r\n  has_many :characters, through: :play_as_characters\r\n  has_many :play_as_characters\r\n  has_many :opponents, through: :play_against_characters, source: :character\r\n  has_many :play_against_characters\r\n\r\n  validates_presence_of :characters\r\n  validates_presence_of :opponents\r\nend\r\n```\r\n\r\nI've tried shoveling in some characters and opponents but it doesn't work :( \r\n\r\nPlayersController\r\n```ruby\r\nclass PlayersController < OpenReadController\r\n  before_action :set_player, only: [:show, :update, :destroy]\r\n\r\n  def create\r\n\r\n    if current_user\r\n      @player = Player.new(player_params)\r\n      @characters = Character.find(params[:characters]) # i've also tried params[:id]\r\n      @opponents = Character.find(params[:opponents])\r\n      @player.characters << @characters\r\n      @player.opponents << @opponents\r\n\r\n\r\n      if @player.save\r\n        # @player.characters << @character\r\n        # @player.opponents << @character\r\n        render json: @player, status: :created, location: @player\r\n      else\r\n        render json: @player.errors, status: :unprocessable_entity\r\n      end\r\n\r\n    else\r\n      head :bad_request\r\n    end\r\n  end\r\n\r\nprivate\r\n\r\n    def set_player\r\n      @player = Player.find(params[:id])\r\n    end\r\n\r\n    def player_params\r\n      params.require(:player).permit(:name, :rank, :characters, :opponents)\r\n    end\r\nend\r\n```"},"comment":{"url":"https://api.github.com/repos/ga-wdi-boston/capstone-project/issues/comments/205967642","html_url":"https://github.com/ga-wdi-boston/capstone-project/issues/99#issuecomment-205967642","issue_url":"https://api.github.com/repos/ga-wdi-boston/capstone-project/issues/99","id":205967642,"user":{"login":"seatuna","id":16471076,"avatar_url":"https://avatars.githubusercontent.com/u/16471076?v=3","gravatar_id":"","url":"https://api.github.com/users/seatuna","html_url":"https://github.com/seatuna","followers_url":"https://api.github.com/users/seatuna/followers","following_url":"https://api.github.com/users/seatuna/following{/other_user}","gists_url":"https://api.github.com/users/seatuna/gists{/gist_id}","starred_url":"https://api.github.com/users/seatuna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/seatuna/subscriptions","organizations_url":"https://api.github.com/users/seatuna/orgs","repos_url":"https://api.github.com/users/seatuna/repos","events_url":"https://api.github.com/users/seatuna/events{/privacy}","received_events_url":"https://api.github.com/users/seatuna/received_events","type":"User","site_admin":false},"created_at":"2016-04-05T19:55:23Z","updated_at":"2016-04-05T19:55:23Z","body":"okie dokie x_X"}}