[英]No route matches, form_tag ,ruby on rails
route.rb文件:
get "dcrelations/create"
get "dcrelations/destroy"
resources :dcrelations
match 'derelations/create' => 'dcrelations#create'
match 'derelations/destroy' => 'dcrelations#destroy'
表格文件:
<%= 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 'shared/dcrelation_form' %>
控制器文件:
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
錯誤頁面
Routing Error
No route matches [POST] "/dcrelations/create"
Try running rake routes for more information on available 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
伙計們,我只想使用form_tag來更新數據庫。 我被這個錯誤困住了,已經搜索了幾個小時。 感謝您的所有幫助!!!!
從form_tag聲明中刪除action => :create
。
根據您的傾斜路線,POST解析為dcrelations#create的唯一路線是URI /dcrelations(.:format)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.