LoginSignup
13
9

More than 5 years have passed since last update.

テンプレートがあるかないか調べる

Posted at

app/views/posts/_formのpartialがあるかどうか知りたい時

lookup_context.exists?('form', 'posts', true)

参考URLのstackoverflowでは例外を使ったやりかたも紹介されていた

<%= render :partial => "#{dynamic_partial}" rescue render :partial => 'partial_that_actually_exists' %>

参考
http://api.rubyonrails.org/classes/ActionView/LookupContext/ViewPaths.html#method-i-find_template
http://stackoverflow.com/questions/3559419/is-there-any-rails-function-to-check-if-a-partial-exists

13
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
9