_applicant.html.erb 中的链接在浏览器中如下所示:http://localhost:3000/needs/3/applicants.1
单击此链接时会在浏览器中显示:
Routing Error
No route matches [PUT] "/needs/3/applicants.1"
我希望它更新此特定申请人行的接受列。基本上我希望它将数据发送到申请者控制器的更新方法。我怎样才能修改代码来做到这一点?
_applicant.html.erb
<%= link_to 'Accept Applicant', need_applicants_path(applicant.need_id, applicant.id), :method => :put, :action => "update", :applicant => {:acceptance => true} %>
从运行 rake 路线得到这个:
PUT /needs/:need_id/applicants/:id(.:format) applicants#update
路线.rb:
resources :needs, except: [:new] do
resources :applicants
end
申请人控制器.rb
class ApplicantsController < ApplicationController
def update
@need = Need.find(params[:need_id])
@applicant = @need.applicants.find(params[:id])
if @applicant.update_attributes(params[:applicant])
flash[:success] = 'Your applicant has been accepted/rejected!'
redirect_to @need
else
@need = Need.find(params[:need_id])
render 'needs/show'
end
end
end