ノード名を表示するノードを生成しますが、エラーです。ここにコモがあります。Railsエラー: 'id' = indexのノードが見つかりませんでしたか?
コントローラ/ nodes_controller.rb(デフォルト)
class NodesController < ApplicationController
before_action :set_node, only: [:show, :edit, :update, :destroy]
def index
@nodes = Node.all
end
def show
@node = Node.find(params[:id])
end
def new
@node = Node.new
end
def edit
end
def create
@list = Node.new(node_params)
respond_to do |format|
if @node.save
format.html { redirect_to @node, notice: 'Node was successfully created.' }
format.json { render :show, status: :created, location: @node }
else
format.html { render :new }
format.json { render json: @list.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /lists/1
# PATCH/PUT /lists/1.json
def update
respond_to do |format|
if @node.update(node_params)
format.html { redirect_to @node, notice: 'Node was successfully updated.' }
format.json { render :show, status: :ok, location: @node }
else
format.html { render :edit }
format.json { render json: @node.errors, status: :unprocessable_entity }
end
end
end
# DELETE /lists/1
# DELETE /lists/1.json
def destroy
@node.destroy
respond_to do |format|
format.html { redirect_to nodes_url, notice: 'Node was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_node
@node = Node.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def node_params
params.require(:node).permit(:name, :summary)
end
end
モデル/ node.rb
class Node < ActiveRecord::Base
has_many :lists
end
ビュー/ノード/ index.html.erb
<div class="nodes_list">
nodes: <br> <br>
<% nodes.each do |node| %>
<button class="secondary hollow button tiny">
<% if list.node %>
<%= link_to node.name, node %>
<% end %>
</button>
<% end %>
</div>
routes.rbを
Rails.application.routes.draw do
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
resources :lists, only: [:index, :show, :new, :create]
resources :nodes, only: [:show, :index, :create, :new]
root 'lists#index'
end
本の
レールのhttp://localhost:3000/nodes/index
ActiveRecord::RecordNotFound in NodesController#show
Couldn't find Node with 'id'=index
Extracted source (around line #61):
# Use callbacks to share common setup or constraints between actions.
60 def set_node
61 @node = Node.find(params[:id])
62 end
Request
Parameters:
{"id"=>"index"}
私は何をすべき?デバッグするには?ありがとうございます。
あなたが間違ったルートになるだろう。インデックスは '/ nodes /'にあり、ルート '/ nodes/index'はIDの' 'index 'でSHOWをレンダリングしようとしています – tpbowden
' http:// localhost:3000/nodes/indexのようなURLを手動で入力していますか? '? – Pavan
ああ、私の神。知っている。私はとても不注意です。今はすべてがOKです。 – dongdongxiao