Reputation: 27124
I'm trying to use render_to_string
by its default nature in my console..
StoresController.new.render_to_string '/shared/colors'
This returns :
ActionView::MissingTemplate: Missing template /shared/colors with {:locale=>[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip, :srt], :handlers=>[:erb, :builder, :coffee, :haml]}. Searched in:
* "/Sites/whisper.me/app/views"
* "/.rvm/gems/ruby-1.9.3-p125@project/gems/teaspoon-0.7.7/app/views"
* "/.rvm/gems/ruby-1.9.3-p125@project/gems/devise-2.2.2/app/views"
* "/Sites/project"
* "/"
Even though my partial is clearly there. In fact, if I have it search for any file in any directory with any controller, it also doesn't work as expected. What am I missing?
Upvotes: 0
Views: 394
Reputation: 5251
Are you sure that '/shared/colors'
should work? Following Rails Guide I would try the following instead:
StoresController.new.render_to_string 'shared/colors'
The leading slash seems to determine a file system path:
The render method can also use a view that's entirely outside of your application [...]. Rails determines that this is a file render because of the leading slash character.
Upvotes: 0
Reputation: 53048
Use this
StoresController.new.render_to_string partial: '/shared/colors'
Give partial
option as you are trying to render a partial.
Upvotes: 1