简体   繁体   English

没有路线匹配,form_tag,在铁路上的红宝石

[英]No route matches, form_tag ,ruby on rails

routes.rb file: route.rb文件:

get "dcrelations/create" 
get "dcrelations/destroy"
resources :dcrelations
match 'derelations/create' => 'dcrelations#create'
match 'derelations/destroy' => 'dcrelations#destroy'

form file: 表格文件:

<%= form_tag(:controller => "dcrelations", :action => "create", :method => "post") do %>
  <div class="field">
    <%= hidden_field_tag(:clinic_id, @clinic.clinic_id) %>
    <%= label_tag(:doctor_id, "doctor_id: ") %><br />
    <%= number_field_tag(:doctor_id) %>
  </div>
  <%= submit_tag("Add Doctor") %>
<% end %>

render form file: 渲染表单文件:

<%= render 'shared/dcrelation_form' %>

controller file: 控制器文件:

def create
  @dcrelation = Dcrelation.new(params[:clinic_id],params[:doctor_id])
  if @dcrelation.save
    flash[:success] = "doctor added!"
    redirect_to root_url
  else
    render 'clinic/show'
  end
  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @clinic }
  end
end

error page 错误页面

Routing Error
No route matches [POST] "/dcrelations/create"
Try running rake routes for more information on available routes. 

rake routes 耙路

dcrelations_create  GET /dcrelations/create(.:format)  dcrelations#create
dcrelations_destroy GET /dcrelations/destroy(.:format) dcrelations#destroy
    dcrelations GET    /dcrelations(.:format)          dcrelations#index
                POST   /dcrelations(.:format)          dcrelations#create
 new_dcrelation GET    /dcrelations/new(.:format)      dcrelations#new
edit_dcrelation GET    /dcrelations/:id/edit(.:format) dcrelations#edit
     dcrelation GET    /dcrelations/:id(.:format)      dcrelations#show
                PUT    /dcrelations/:id(.:format)      dcrelations#update
                DELETE /dcrelations/:id(.:format)      dcrelations#destroy
           root        /                               onedoc#home
         create        /create(.:format)               dcrelations#create
        destroy        /destroy(.:format)              dcrelations#destroy

guys, i just want to use form_tag to update the db. 伙计们,我只想使用form_tag来更新数据库。 I got stucked by this error and have been searching for few hours. 我被这个错误困住了,已经搜索了几个小时。 Appreciated for all your help!!!!! 感谢您的所有帮助!!!!

Remove action => :create from your form_tag declaration. 从form_tag声明中删除action => :create

Per your raked routes, the only route you have for a POST to resolve to dcrelations#create is to the URI /dcrelations(.:format) 根据您的倾斜路线,POST解析为dcrelations#create的唯一路线是URI /dcrelations(.:format)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM