我有一个模型<代码>Patients,该模型有许多<编码>健康计划。 我试图通过在点击“补充保险计划”链接时插入适当的表格,更新病人的健康计划。
在点击上适当插入这些领域,但在提交表格时,我有以下错误:
No route matches [POST] "/patients/1472"
当我检查表格中产生的代码时,它并不以PUT方法制造隐蔽的现场,以压倒缺的POST方法。 这造成了错误,因为没有PPOST航道。 有趣的是,如果我把表格直接贴在显示.html.erb之内的话,它就会正确显示,而PUT方法的隐蔽领域也得到适当生成。 当我用小 j子补充部分表格时,法国食品安全局会这样做。
我花了几个小时的时间,对法典进行了研究,对StackOverflow和Almighty 谷歌进行了研究。
我的发言如下:
<%= form_for @patient do |f| %>
<%= fields_for :healthplans_attributes do |builder| %>
<td><%= builder.text_field :company %></td>
<td><%= builder.hidden_field :_destroy %><%= link_to_remove_fields "remove", f %></td>
<% end %>
<td><%= f.submit "Submit" %></td>
<% end %>
我的控制员(删除了极端职能):
class PatientsController < ApplicationController
helper_method :sort_column, :sort_direction
def index
def show
@patient = Patient.find(params[:id])
@insurance = Patient.return_insurances(@patient)
@pa = @patient.preauthorizations
@programs = @patient.programs
@billingitems = Claim.return_billingitems(@patient, params[:page])
@address = Patient.return_address(@patient)
@phone = Patient.return_phone(@patient)
end
def new
@patient = Patient.new
1.times { @patient.healthplans.build }
1.times { @patient.preauthorizations.build }
1.times { @patient.programs.build }
render :url => new.html , :layout => "false"
end
def new_insurance
@patient = Patient.find(params[:id])
respond_to do |format|
format.html
format.js { @patient }
end
end
def create
# raise params.inspect
@patient = Patient.new(params[:patient])
if @patient.save
flash[:notice] = "Successfully created patient."
redirect_to @patient
else
render :action => new
end
end
def edit
@patient = Patient.find(params[:id])
end
def update
@patient = Patient.find(params[:id])
if @patient.update_attributes(params[:patient])
flash[:notice] = "Successfully updated patient."
redirect_to @patient
else
render :action => edit
end
end
我认为,我与《附加保险计划》的联系是:
<tr>
<td colspan="7">
<table id="insurances"> </table>
</td>
<tr>
<td>
<%= link_to "Add Insurance Plan", new_insurance_patient_path(:id => @patient.id), :remote => true %>
</td>
</tr>
The new_ Insurance.js.erb file:
J(function(){
var html = <%= escape_javascript(raw render(:partial => add_insurance )) %> ;
J("#insurances").append(html);
});
导致部分“再保险”。
<tr class="fields" >
<%= form_for @patient do |f| %>
<%= fields_for :healthplans_attributes do |builder| %>
<td><%= builder.text_field :company %></td>
<td><%= builder.hidden_field :_destroy %><%= link_to_remove_fields "remove", f %></td>
<% end %>
<td><%= f.submit "Submit" %></td>
<% end %>
</tr>
最后,我的道路。 rb file:
Billspace::Application.routes.draw do
# The priority is based upon order of creation:
# first created -> highest priority.
match patients/set_active_flag/:id , :to => patients#set_active_flag
match patients/active_list , :to => patients#active_list
match patients/inactive_list , :to => patients#inactive_list
match payments/show_payment_items/:id , :to => billingitems#show_payment_items
match claims/claiminfo/:id , :to => claims#claiminfo
match claiminfo/:id , :to => claims#claiminfo
match patients/new , :to => patients#new
match claims/new/create_claims , :to => claims#create_claims
match payments , :to => billingitems#index
resources :billingitems
resources :claims
resources :providers
resources :patients
resources :patients do
member do
get new_program
get new_insurance
end
end
match signup , :to => users#new , :as => signup
match logout , :to => sessions#destroy , :as => logout
match login , :to => sessions#new , :as => login
resources :sessions
resources :users
end
感谢。