Reputation: 388
In my application teams are created to solve a challenge. Once the team is created, members can join that team.
Everything works when creating the challenge -> the team, but when it comes to adding the team member that is when I receive this error:
Error
NoMethodError in Team_members#new
Showing /home/vincent/solvabl/app/views/team_members/_form.html.erb where line #1 raised:
undefined method `team_team_members_path' for #<#<Class:0x9bdadcc>:0xa179df0>
Extracted source (around line #1):
1: <%= form_for([@challenge,@team,@team_member]) do |f| %>
2: <% if @team_member.errors.any? %>
3: <div id="error_explanation">
4: <h2><%= pluralize(@team_member.errors.count, "error") %> prohibited this team_member from being saved:</h2>
Trace of template inclusion: app/views/team_members/new.html.erb
Rails.root: /home/vincent/solvabl Application Trace | Framework Trace | Full Trace
app/views/team_members/_form.html.erb:1:in `_app_views_team_members__form_html_erb___477348688_81202980'
app/views/team_members/new.html.erb:3:in `_app_views_team_members_new_html_erb___135218923_85112930'
app/controllers/team_members_controller.rb:36:in `new'
Request
Parameters:
{"challenge_id"=>"1",
"team_id"=>"1"}
Show session dump
Show env dump Response
Headers:
None
Routes
resources :challenges do
resources :teams do
resources :team_members
end
end
Controller
def create
@team_member = TeamMember.new(params[:team_member])
@team_member.team_id = @team.id
@team_member.user_id = current_user.id
respond_to do |format|
if @team_member.save
format.html { redirect_to [@team,@team_member], notice: 'Team member was successfully created.' }
format.json { render json: [@team,@team_member], status: :created, location: [@team,@team_member] }
else
format.html { render action: "new" }
format.json { render json: @team_member.errors, status: :unprocessable_entity }
end
end
end
View
<%= form_for([@team,@team_member]) do |f| %>
<% if @team_member.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@team_member.errors.count, "error") %> prohibited this team_member from being saved:</h2>
<ul>
<% @team_member.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :team_id %><br />
<%= f.number_field :team_id %>
</div>
<div class="field">
<%= f.label :user_id %><br />
<%= f.number_field :user_id %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Any help is much appreciated!
Upvotes: 1
Views: 366
Reputation: 38645
The routes you have will give you challenges_team_team_members_path
. In order to get team_team_members_path
add the following to your config/routes.rb
:
resources :teams do
resources :team_members
end
Update:
Please note that this addition should be in addition to what you've already defined. So, your routes.rb
would have:
resources :challenges do
resources :teams do
resources :team_members
end
end
resources :teams do
resources :team_members
end
Upvotes: 1