1
在我的應用程序中,創建團隊是爲了解決挑戰。團隊創建後,成員可以加入該團隊。創建挑戰時ROR:嵌套資源:NoMethodError
一切正常 - >球隊,但是當談到加入團隊成員那就是當我收到此錯誤:
錯誤
NoMethodError在Team_members#新
顯示/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>
模板包含的跟蹤:應用程序/視圖/ team_members/new.html.erb
Rails.root:/首頁/文森特/ solvabl 應用程序跟蹤|框架跟蹤|全面跟蹤
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"}
顯示會話轉儲
顯示ENV轉儲 響應
頁眉:
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 %>
任何幫助是非常讚賞!
謝謝vinodadhikary這實際上使很多道理。當我回到我的電腦時,我會試試這個。我會讓你知道這是否有效。再次感謝! –
這工作!再次感謝! –
@ThomasVincentBlomberg,太好了。別客氣。 – vee