Skip to content

Instantly share code, notes, and snippets.

@workmaster2n
Created April 5, 2012 02:15
Show Gist options
  • Save workmaster2n/2307474 to your computer and use it in GitHub Desktop.
Save workmaster2n/2307474 to your computer and use it in GitHub Desktop.
ActiveSupport::HashWithIndifferentAccess Error
<h1>PlayersToTeams#edit</h1>
<%= form_for @players_to_teams do |field| %>
<%= field.fields_for @players_to_teams.player do |f| %>
<%= f.label :IsActive %>
<%= f.text_field :IsActive %>
<% end %>
<%= field.label :BT %>
<%= field.text_field :BT %>
<br/>
<%= field.submit "Save", class: 'btn btn-primary' %>
<% end %>
ActiveRecord::AssociationTypeMismatch in PlayersToTeamsController#update
Player(#70265401931920) expected, got ActiveSupport::HashWithIndifferentAccess(#70265338950760)
Rails.root: /Users/Tyler/Development/Rails/csbb
Application Trace | Framework Trace | Full Trace
app/controllers/players_to_teams_controller.rb:9:in `block in update'
app/controllers/players_to_teams_controller.rb:8:in `update'
Request
Parameters:
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"16RC1DJZxWlkHpPoUA6d2r8xkTRuZ3IPZgJ2ZQS1FJ8=",
"players_to_team"=>{"player"=>{"IsActive"=>"0"},
"BT"=>"throws"},
"commit"=>"Save",
"id"=>"82035"}
Show session dump
Show env dump
Response
Headers:
None
class Player < ActiveRecord::Base
has_many :players_to_teams
has_many :teams, through: :players_to_teams
end
class PlayersToTeam < ActiveRecord::Base
belongs_to :player
belongs_to :team
accepts_nested_attributes_for :player
end
class PlayersToTeamsController < ApplicationController
def edit
@players_to_teams=PlayersToTeam.find(params[:id])
end
def update
@players_to_teams=PlayersToTeam.find(params[:id])
respond_to do |format|
if @players_to_teams.update_attributes(params[:players_to_team])
format.html { redirect_to @players_to_teams, notice: 'Player_to_Team was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @players_to_teams.errors, status: :unprocessable_entity }
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment