1

I am using rails 4 from Suspenders and need to include content from a middleman-blog rack app from a subfolder in a view. In my app, I have the blog content in:

rails root > my_blog > source > index.html.erb.

I have created the view as:

rails root > app > views > welcomes > index.html.haml

The code in my view is:

%h1 Welcome

= render "my_blog/source/index.html.erb"

But when I access the page I get a Missing Partials error and the message says it only looked in the views folder.

How can I render content from a folder outside views?

analyticsPierce
  • 2,979
  • 9
  • 57
  • 81
  • Possible duplicate of http://stackoverflow.com/questions/6081603/how-can-i-add-a-view-path-to-railss-partial-rendering-lookup – San Jul 23 '14 at 10:03
  • I don't think thats a duplicate. That question is about files that are already under the views folder. – analyticsPierce Jul 23 '14 at 14:07
  • Can't you use the accepted answer to append_to or prepend_to the view path, based on ur requirements? – San Jul 23 '14 at 14:27

3 Answers3

1

Have you tried the full path?

= render "#{Rails.root}/my_blog/source/index.html.haml"
pixelearth
  • 13,674
  • 10
  • 62
  • 110
  • I still get the same error: Missing partial /Users/Documents/site/my_blog/source/_index.html.erb Searched in: * "/Users/Documents/site/app/views" – analyticsPierce Jul 23 '14 at 05:25
1

Try this is in your view file:

%h1 Welcome

= render :partial => "my_blog/source/index"

Note: You must have _index.html.erb partial file in the above specified path.

Also, try to change the name from _index.html.erb to _someothername.html.erb, because index.html.erb is usualy a view file for index action. You can avoid the unwanted confusions.

This may help you..!

Thanks!!

Added Lines (Edited):

Please change your file name from

rails root > my_blog > source > index.html.erb.

to

rails root > my_blog > source > _index.html.erb.
Breen ho
  • 1,601
  • 14
  • 23
1

Partial

The problem is Rails is trying to call a partial, which is not what you're trying to call. A partial should have its name preceded with an _underscore, indicating to Rails that it's a partial, hence why you're receiving your error

The reason this is important is because although you're just calling render, you will actually call the partial too

enter image description here

--

Convention

One of the issues you have is that you'll be going against convention in several ways:

  • MVC dictates the "view" will be loaded per request (so Rails will expect it to just be present whenever you use it)

  • The "partials" functionality of your system needs to add to the views you're showing the users. This means you have to be sure you have a view already showing on screen

This means you need to be certain if you're meant to be using a partial or other element in this part of your app. From the looks of it, whilst you may be doing something right, you need to be sure you're able to load the partial correctly:

<%= render "your/partial/path/_partial_name.html.erb %>

--

View Path

Further to your view path issue, although I've never encountered this issue directly, there is a function called append_view_path, which allows you to add another "path" to look at for your app:

#app/controllers/welcome_controller.rb
Class WelcomeController < ApplicationController
    append_view_path(File.join(RAILS_ROOT, "app/themes/#{@current_theme}"))
end
Richard Peck
  • 76,116
  • 9
  • 93
  • 147