この問題に関する多くの質問/回答を読んでいますが、私の修正が見つからないようです。ルーティングエラー - [POST]と一致するルートがありません
ここに問題があります。私は、注釈の単純な登録を作成するためのRailsの開始に従っています。フォームが機能します - 新しい&注釈を追加できます。
- この:私は、インデックスへのリンクを追加する場合しかし、私は、ルーティングエラーが発生します
<%= button_to "Details", annotation_path(annotation), :class => "btn btn-primary btn-xs"%>
結果で:Noルートマッチ[POST] "/注釈/ 5" - この:
<%= button_to "Add Annotation", new_annotation_path, :class => "btn btn-primary btn-xs"%>
へのルートがない試合[POST] "/注釈/新しい" ヘルプRoutes.dbため
ありがとう:
Rails.application.routes.draw do
root 'dashboard#index'
devise_for :users
resources :users, :annotations
コントローラー:
class AnnotationsController < ApplicationController
def index
@annotations = Annotation.all
end
def show
@annotation = Annotation.find(params[:id])
end
def new
@annotation = Annotation.new
end
def edit
@annotation = Annotation.find(params[:id])
end
def create
@annotation = Annotation.new(annotation_params)
@annotation.save
redirect_to @annotation
end
def update
@annotation = Annotation.find(params[:id])
if @annotation.update(annotation_params)
redirect_to @annotation
else
render 'edit'
end
end
def destroy
@annotation = Annotation.find(params[:id])
@annotation.destroy
redirect_to annotations_path
end
private
def annotation_params
params.require(:annotation).permit(:name, :description)
end
end
、フォーム上形態(=部分)
<%= simple_form_for @annotation, url: annotations_path, html: { class: 'form-horizontal' },
wrapper: :horizontal_form,
wrapper_mappings: {
check_boxes: :horizontal_radio_and_checkboxes,
radio_buttons: :horizontal_radio_and_checkboxes,
file: :horizontal_file_input,
boolean: :horizontal_boolean
} do |f| %>
<%= f.error_notification %>
<%= f.input :name, placeholder: 'Enter name' %>
<%= f.input :description, placeholder: 'Description' %>
<%= f.input :file, as: :file %>
<%= f.input :active, as: :boolean %>
<%= f.input :choice, as: :check_boxes,
collection: [
'Option one ...',
'Option two ...'] %>
<%= f.input :documenttype, as: :radio_buttons,
collection: ['Type1', 'Type2'] %>
<%= f.button :submit %>
<% end %>
注:無駄に、私は<%= simple_form_for :annotation, url: annotations_path,
アドオン 'メソッド::GET'。 'button_to'はそれらのルートが' GET'の間に 'POST'リクエストをデフォルトで行います – kiddorails
また、私はエラーログを慎重に調査することを強く勧めます。質問自体には、「POST」ルートが一致していないと表示されます。ルートが存在しないことを意味します。その理由を確認できます。 – kiddorails
[ルーティングエラー - カスタムアクションでボタン\ _toを使用すると経路が一致しません]の重複可能性があります(http://stackoverflow.com/questions/12650213/routing-error-no-route-matches-when-using-button-to -with-custom-action) – kiddorails