質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

636閲覧

<%= render @feed_items %>でパーシャルがレンダリングできない

退会済みユーザー

退会済みユーザー

総合スコア0

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2019/12/10 17:46

Rails Tutorialを参考にユーザーとフォローユーザーの投稿内容を表示させたいのですが、パーシャルが上手くいかず困っております。似たような過去ケースがありましたが、どうもそれとは違うと思うのでここで質問させていただきました。
エラーメッセージ
ActionView::MissingTemplate in StaticPages#home

### 該当のソースコード [app/views/shared/_feed.html.erb] <% if @feed_items.any? %> <ol class="tweets"> <%= render @feed_items %>⬅︎エラーあり </ol> <%= will_paginate @feed_items %> <% end %> ### 該当のソースコード [app/views/static_pages/home.html.erb] <% provide(:title, "Home") %> <% if logged_in? %> <div class="row"> <aside class="col-md-4"> <section class="user_info"> <%= render 'shared/user_info' %> </section> <section class="stats"> <%= render 'shared/stats' %> </section> </aside> <div class="col-md-8"> <h3>フィード</h3> <%= render 'shared/feed' %>⬅︎エラーあり </div> </div> <% else %> . . .

以下、コントローラー、モデルになります。

[app/controllers/static_pages_controller.rb] lass StaticPagesController < ApplicationController def home if logged_in? @tweets = current_user.tweets.build @feed_items = current_user.feed.paginate(page: params[:page]) end end def about end end
[app/model/user.rb] class User < ApplicationRecord has_many :tweets,dependent: :destroy has_many :comments, dependent: :destroy has_many :active_relationships, class_name: "Relationship", foreign_key: "follower_id", dependent: :destroy has_many :passive_relationships, class_name: "Relationship", foreign_key: "followed_id", dependent: :destroy has_many :following, through: :active_relationships, source: :followed has_many :followers, through: :passive_relationships, source: :follower before_save { self.email = email.downcase } validates :name, presence: true, length: { maximum: 50 } validates :username, presence: true, length: { maximum: 50 } VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+.[a-z]+\z/i validates :email, presence: true, length: { maximum: 255 }, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false } has_secure_password validates :password, presence: true, length: { minimum: 6 } #フィード表示 def feed following_ids = "SELECT followed_id FROM relationships WHERE follower_id = :user_id" Tweet.where("user_id IN (#{following_ids}) OR user_id = :user_id", user_id: id) end . . .
[app/views/tweets/new.html.erb] <% provide(:title, '投稿') %> <h1>投稿フォーム</h1> <div class="row"> <div class="col-md-6 col-md-offset-3"> <%= form_for @tweet do |f| %> <%= render 'shared/error_messages', object: f.object %> <%= f.label :comment %> <%= f.text_field :comment, class: 'form-control' %> <%= f.label :picture %> <%= f.file_field :picture %> <%= f.submit "投稿", class: "btn btn-primary" %> <% end %> </div> </div>

全角が混じっていないかをチェックしましたが、そこは問題ありませんでした。user.rbの
Tweet.where("user_id IN (#{following_ids})
OR user_id = :user_id", user_id: id)

Tweets.where("user_id IN (#{following_ids})
OR user_id = :user_id", user_id: id)

にしてみたところ、uninitialized constant User::Tweetsのエラーが発生するので、ここの問題ではないかと思います。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

KazuSaka

2019/12/10 19:33

可能性薄いと思いますが、<%= render 'shared/feed' %>で呼び出してるパーシャルのファイル名は合ってますよね?ここがアンマッチだと、MissingTemplateエラーが出ると思うので。 ただ、パーシャル内の所で、エラーが出ているとのことなので問題なさそうですが、、、一応
winterboum

2019/12/10 21:06

render @feed_items でどのpartialを開くつもりですか? エラーメッセージの省略されてる所にどのpartialを探しているか書かれていると思います。それと合ってますか?
guest

回答1

0

ベストアンサー

こちら自己解決しました。パーシャルで引っ張ってくる_tweet.html.erbの名前を「tweets」.html.erbとしていたのが原因でした。

投稿2019/12/12 17:35

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問