前提・実現したいこと
Rails Tutorial 13.3.2の演習問題を問いているところ、気になるところがありました。
演習問題は、パーシャルを利用してHOMEページをリファクタリングしろとのことで、以下のように記述したところ、アプリケーションは動くのですがunittestでエラーがでました。
テストのエラー
Error: MicropostsInterfaceTest#test_micropost_interface: ActionView::Template::Error: Missing partial microposts/_logged_in, application/_logged_in with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :coffee, :jbuilder]}. Searched in: * "/home/ec2-user/environment/sample_app/app/views" app/views/static_pages/home.html.erb:2:in `_app_views_static_pages_home_html_erb___2443717471996564898_60904740' app/controllers/microposts_controller.rb:12:in `create' test/integration/microposts_interface_test.rb:16:in `block (2 levels) in <class:MicropostsInterfaceTest>' test/integration/microposts_interface_test.rb:15:in `block in <class:MicropostsInterfaceTest>'
なぜ、以下のコードでは正しくないのでしょうか。
該当のソースコード(HOMEページ)
<% if logged_in? %> <%= render 'logged_in' %> <% else %> <%= render 'without_logged_in' %> <% end %>
試しに、以下のように、フォルダー名から記述したところテストが正しく動きました。
試したこと
<% if logged_in? %> <%= render 'static_pages/logged_in' %> <% else %> <%= render 'static_pages/without_logged_in' %> <% end %>
補足情報(FW/ツールのバージョンなど)
HOMEページのファイルとlogged_in.html.erbやwithout_logged_in.html.erbファイルが置かれているフォルダーは同じなので、フォルダー名を省略しても動くだろうと思うのですが、なぜ正しく動かなかったのか疑問です。
###補足情報2
エラーメッセージを見ると
Missing partial microposts/_logged_in, application/_logged_in
とあることから、micropostsコントローラからrenderでstatic_pages/home.html.erbを表示しているのですが、その場合は、renderした元コントローラに対応するview内のパーシャルを探すようになっているのでしょうか。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/09/30 06:57
2018/10/01 02:19 編集
2018/10/04 12:50 編集