在我的应用程序中,创建团队是为了解决挑战。创建团队后,成员可以加入该团队。
创建挑战 -> 团队时一切正常,但在添加团队成员时,我收到此错误:
错误
Team_members 中的 NoMethodError#new
显示 /home/vincent/solvabl/app/views/team_members/_form.html.erb 其中第 1 行提出:
undefined method `team_team_members_path' for #<#<Class:0x9bdadcc>:0xa179df0>
提取的源代码(在第 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>
模板包含的痕迹:app/views/team_members/new.html.erb
Rails.root:/home/vincent/solvable 应用程序跟踪 | 框架跟踪 | 全跟踪
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'
要求
参数:
{"challenge_id"=>"1",
"team_id"=>"1"}
显示会话转储
显示环境转储响应
标题:
None
路线
resources :challenges do
resources :teams do
resources :team_members
end
end
控制器
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
看法
<%= 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 %>
任何帮助深表感谢!