Rails Solutions:Rails Made Easyという本をフォローしています。Rails2用に書かれていますが、Rails 3を使用しているので、非常に面白く、多くのことを学ぶことができます。上記の問題。Stackや他のウェブサイトで読んだことがありますが、これはルートの問題である可能性があると思いますが、これまでのところ、この本ではルートについて何も言及されていません。
ルート.rb
List::Application.routes.draw do
match ':controller(/:action(/:id))(.:format)'
end
app / views / classes / show.html.erb
<p>
<strong>Title: </strong> <%= @classified.title %><br />
</p>
app / controllers / classes_controller.rb
class ClassifiedController < ApplicationController
def list
@classifieds = Classified.find(:all)
end
def show
@classifieds = Classified.find(params[:id])
end
def new
@classified = Classified.new
end
def create
@classified = Classified.new(params[:classified])
if @classified.save
redirect_to :action => 'list'
else
render :action => 'new'
end
end
def edit
end
def update
end
def delete
end
end
Classified#showのNoMethodError
/home/mark/Documents/RoR/list/app/views/classified/show.html.erbを表示しています。3行目が表示されています。
nilの未定義メソッド`title':NilClass抽出されたソース(3行目あたり):
1:2:
3: タイトル: <%= @ classes.title%>
4: