Rails4で新しいプロジェクトを作成し、フォームから値を登録しようとしたら
moduleがないというエラーとなりました。 モデルが読み込まれていないようなのですが
解決方法が見つからず、どなたかご教授いただければと存じます
※DBは標準のSQL LITEになります
class BlogController < ApplicationController def index end def new end def create @blog = Blog.new(blog_params) @blog.save redirect_to @blog end private def blog_params params.require(:blog).permit(:title, :text) end end
newページ
<h1>新しい記事を投稿</h1> <%= form_for :blog, url: blog_index_path do |f| %> <p> <%= f.label :title, "記事のタイトル" %><br> <%= f.text_field :title %> </p> <p> <%= f.label :text, "記事の内容" %><br> <%= f.text_area :text, cols: 60, rows: 8 %> </p> <p> <%= f.submit %> </p> <% end %>
エラー内容
NoMethodError in BlogController#create undefined method `new' for Blog:Module
newページからpostした際の履歴
Started GET "/blog/new" for ::1 at 2018-02-02 20:27:16 +0900 ActiveRecord::SchemaMigration Load (2.3ms) SELECT "schema_migrations".* FROM "schema_migrations" Processing by BlogController#new as HTML Rendered blog/new.html.erb within layouts/application (78.5ms) Completed 200 OK in 557ms (Views: 544.7ms | ActiveRecord: 0.0ms) Started POST "/blog" for ::1 at 2018-02-02 20:27:33 +0900 Processing by BlogController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"i2yibMTuyBV53P1Zm+IxQwJXm4Kd28EodoUSmEsr8RW6amtPiJ8TeCiLpMiI4Fjv2YmL5ZxGQ98OF+pq9wcH2w==", "blog"=>{"title"=>"dadad", "text"=>"dada"}, "commit"=>"Save Blog"} Completed 500 Internal Server Error in 1ms (ActiveRecord: 0.0ms) NoMethodError (undefined method `new' for Blog:Module): app/controllers/blog_controller.rb:12:in `create'
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/02/03 00:57