###前提・実現したいこと
rails tutorialの2.3.3演習1についての質問です。
「ユーザーのshowページを編集し、ユーザーの最初のマイクロポストを表示してみましょう。同ファイル内の他のコードから文法を推測してみてください。うまく表示できたかどうか、/users/1 にアクセスして確認してみましょう。」
という問題です。
users_controller.rbに下記のように@micropost = Micropost.find(params[:id])を追加 def set_user @user = User.find(params[:id]) @micropost = Micropost.find(params[:id]) end ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー usersのshow.html.erbに下記のように追加 <p> <strong>Content:</strong> <%= @micropost.content %> </p>
googleで調べたところこのようにするとユーザーのshowページに表示されると書かれていたのですがうまくいきません。
なのでusers_controller.rbの@micropost = Micropost.find(params[:id])の.findを.whereに変更したのですが今度は「NoMethodError in Users#show」「undefined method `content' for #Micropost::ActiveRecord_Relation:0x007fe3757f9558」というエラーが出ました。
migrationファイルはこれです。
class CreateMicroposts < ActiveRecord::Migration[5.1] def change create_table :microposts do |t| t.text :content t.integer :user_id t.timestamps end end end