Нет совпадений маршрутов, 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 для обновления БД. Я застрял из-за этой ошибки и искал несколько часов. Признателен за всю вашу помощь!!!!!


person SCV    schedule 09.06.2013    source источник


Ответы (1)


Удалите action => :create из объявления form_tag.

В соответствии с вашими рейковыми маршрутами единственный маршрут, который у вас есть для POST для разрешения dcrelations#create, — это URI /dcrelations(.:format)

person mynameiscoffey    schedule 09.06.2013
comment
Давайте правильно ответим!!! Спасибо большое. Не могли бы вы сказать мне, почему? почему нам не нужно action:create, но программист знает, что это для метода create, потому что у меня есть и метод destroy. - person SCV; 09.06.2013
comment
Руководство по маршрутизации Rails хорошо объясняет, почему это поведение работает именно так, как оно есть, обратите особое внимание на раздел 2.2 guides.rubyonrails.org/routing.html - person mynameiscoffey; 09.06.2013