Skip to content

Instantly share code, notes, and snippets.

@glennmartinez
Created June 2, 2013 04:55
Show Gist options
  • Select an option

  • Save glennmartinez/5692659 to your computer and use it in GitHub Desktop.

Select an option

Save glennmartinez/5692659 to your computer and use it in GitHub Desktop.
I'm getting the following error when posting a form: Couldn't find Team without an ID
I have the below post parameters
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"knq4dG1U/5NJxMD6KYxfOpKd3CuOBHRlp6xCwdpwCnQ=",
"match"=>{"name"=>"latest match",
"date(1i)"=>"2013",
"date(2i)"=>"5",
"date(3i)"=>"19",
"teams_attributes"=>{"1368967240149"=>{"name"=>"Navi",
"id"=>"1"}}},
"commit"=>"Update Match",
"match_id"=>"2"}
Model:
team has_many :matchips
team has_many :matches :through => matchips
match has_many :matchips
match has_many :teams :through => matchips
Teams Controller:
def create
@team = Team.find(params[:team_id]) <-----fails here!
redirect_to @match
end
form:
<%= nested_form_for @match, :url => {:action => "add_team_to_match_post"} do |f| %>
<% if @match.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@match.errors.count, "error") %> prohibited this match from being saved:</h2>
<ul>
<% @match.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :date %><br />
<%= f.date_select :date %>
</div>
<%= f.fields_for :teams, :html => { :class => 'form-vertical' } do |builder| %>
<%= builder.label "Team Name:" %>
<%= builder.autocomplete_field :name, autocomplete_team_name_teams_path, :update_elements => {:id => "##{form_tag_id(builder.object_name, :id)}" },:class => "input-small",:placeholder => "Search" %>
<%= builder.hidden_field :id %>
<% end %>
<%= f.link_to_add raw('<i class="icon-plus-sign"></i>'), :teams, :class => 'btn btn-small btn-primary' %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment