前提・実現したいこと
railsを使ってtwitterのような投稿データを扱う一覧画面/詳細画面/登録画面/編集画面を作ろうと
rails new tweet_app -d postgresql
bin/rails db:create
そしてモデルを作成してmigrateする前に
gemfileに
gem 'slim-rails'
gem 'html2slim'をbundleし
bundle exec erb2slim app/views/layouts/ --deleteを実行して
slim形式で記述するようにしてから
ここで
rails generate model Post name:string context:text
bin/rails db:migrateを実行し
rails generate controller posts index show new editを実行して
実際にルーティング、コントローラ、ビューをいじってブラウザに表示されるか試したのですが
PostsController#index is missing a template for this request format and variant. request.formats: ["text/html"] request.variant: [] NOTE! For XHR/Ajax or API requests, this action would normally respond with 204 No Content: an empty white screen. Since you're loading it in a web browser, we assume that you expected to actually render a template, not nothing, so we're showing an error to be extra-clear. If you expect 204 No Content, carry on. That's what you'll get from an XHR or API request. Give it a shot.
というエラーメッセージが出てしまいブラウザに表示させることができません汗
一覧画面の例だと
ルーティングの中身としては
root to: 'posts#index'
resources :posts
コントローラの中身としては
def index
@posts=Post.all
です。
ビューはapp/views/posts/index.html.slim
という名前でこれのslim部分をerbとrenameするとブラウザには表示されるのですが
slimのままではこのエラーメッセージが出てしまうのです汗
どなたか解決策がわかる方おたすけくださいm(_ _)m
あなたの回答
tips
プレビュー