English 中文(简体)
铁路3在通过舱位部分展示造成路程错误时,忽视了PUT方法
原标题:Rails 3 ignores PUT method when form partial displayed via jquery causing routing error

我有一个模型<代码>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">&nbsp;</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

感谢。

最佳回答

我有同样的问题(使用铁路为3.2.8)。 自你问这个问题以来已经6个月了,而且你或许早就解决了这个问题或放弃了,但为了未来的神职人员,我把这一回答说了。

这里似乎的问题是,正如我一样,你在<tr>内,但在任何<td>内没有。 <form> tags, but not for the <div> tag rails use toannex theidden submissions, asprofile (or potential-visible) content such as tags naturen t be made in such a place. 显然,当铁路从一纸 file中产生一页时,它就没有问题了,但是,如果要求 j铁地和obviously不正确的东西,则会 silent弃该违法行为的<div>及其所有内容。 为我工作的解决办法是,在自己看不到的<td>上附上标记,例如:

<td style="display:none">
    <%= form_for @patient do |f| %>
</td>

这似乎满足了以下条件:你是带上<div>,直接在<tr> s内,表格已作为方案主管机构正式提交。

问题回答

暂无回答




相关问题
Rails: Proxy Pass?

I ve got a web-app that I want to migrate to Rails, which is currently just plain HTML with an Apache proxy to another server, running a custom database/webserver that serves the site s dynamic ...

MVC routing is not handling one of my directories

I m using ASP.NET MVC with IIS 7.0. I ve got 404 errors hooked up fine through my Application_Error override. In addition to "Controllers", "Models", "Helpers" etc. I have a directory called Files ...

Ruby on Rails conditional routing

I have a site listing many jobs, but I also want each account to be able to access its jobs in one place. Thus, I am using these routes: map.resources :jobs map.resource :account, :has_many => :...

Clean URL s using OpenCart s router class

How do you write clean URL s in OpenCart using their built in Router class? Here is my .htaccess file: RewriteEngine On RewriteRule ^(system) - [F,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{...

subdomain routing to multiple controller issue

I have a site: www.mydomain.com where we have administrative controls hidden away from normal customer view. I would like to only access the administrative features under a subdomain such as admin....

Can controller names in RESTful routes be optional?

With a standard map.resource routing mechanics and several nested resources the resultant routes are unnecessarily long. Consider the following route: site.org/users/pavelshved/blogs/blogging-horror/...

Help with rails routes

Im having a little trouble setting up routes. I have a users controller/model/views set up restfully so users is set up to be a resource in my routes. I want to change that to be usuarios ...

热门标签