NoMethodError in Articles#show
undefined method `title' for nil:NilClass というエラーが出ました。
自分のコードは以下です
articles_controller.rb
Ruby
1 2 def new 3 end 4 5 6 def create 7 @article = Article.new(article_params) 8 @article.save 9 redirect_to article_path(@article) 10 end 11 12 def article_params 13 params.require(:article).permit(:title,:text) 14 end 15 16 def show 17 @article = Article.find params[:id] 18 end 19 20 def index 21 @articles = Article.all 22 end 23 24 25
articles/show.html.erb
Ruby
1 <%= @article.title %> 2 <%= @article.text %>
db/migrate/..._create_articles.rb
Ruby
1class CreateArticles < ActiveRecord::Migration[5.0] 2 def change 3 create_table :articles do |t| 4 t.string :title 5 t.text :text 6 7 t.timestamps 8 end 9 end 10end
どの部分でエラーが起きているのかがわかりません
どなたかお助けください。
よろしくお願いします
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/23 06:54