我正在学习 Ruby on Rails,但遇到了一个问题:
ActiveRecord::RecordNotFound in BookmarksController#show 找不到带有 'id'= 的书签
控制器:
class BookmarksController < ApplicationController
def index
@bookmarks = Bookmark.all
end
def show
@bookmark = Bookmark.find(params[:id])
end
def edit
end
def new
end
end
看法:
<h2>Detail zum Favorit</h2>
<p>Titel: <%= h @bookmark.title %></p>
<p>URL: <%= h @bookmark.url %></p>
<p>Kommentar: <%= h @bookmark.comment %></p>
<p>Erstellt am: <%= @bookmark.created_at %></p>
<p>Geändert am: <%= @bookmark.updated_at %></p>
架构.rb:
create_table "bookmarks", force: :cascade do |t|
t.string "title"
t.string "url"
t.text "comment"
t.datetime "created_at"
t.datetime "updated_at"
end
路线.rb:
Rails.application.routes.draw do
get 'bookmarks/index'
get 'bookmarks/edit'
get 'bookmarks/new'
get 'bookmarks/show'
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
resources :bookmarks
网址:
http://localhost:3000/bookmarks/show
我按照以下说明操作:http: //openbook.galileo-press.de/ruby_on_rails/ruby_on_rails_05_004.htm#mj035976f94f0c66066b0f06b2ffe8e16e