Eugen Soloviov
Eugen Soloviov

Reputation: 306

How to create 1 view for 2 layouts in erb?

I make a project on serve and use erb syntax. I want to compile two files: index.html (compiled with template content) and load.html (only content). I create two layouts (_clear.html.erb (with the only yield) and _default.html.erb) and create a partial (_content_for_page.html.erb).

There are problems with compilation of index.html.erb. According to Rails manual (3.4.3 Partial Layouts) I have to write index.html.erb:

<%= render :partial => "_content_for_page.html.erb", :layout => "_default.html.erb" %>

But it doesn't work. Only partial is compiled. What is wrong?

Upvotes: 2

Views: 154

Answers (1)

SUDO Los Angeles
SUDO Los Angeles

Reputation: 1635

First I just want to point out Serve does not utilize Rails unless the rails gem is included in the Gemfile of your project, but that will do something unexpected considering Serve organizes your project differently than Rails.

Now I don't know if this answers your question, but it may help to know partials should be rendered without the beginning underscore and are usually passed as a symbol.

<%= render :partial => :content_for_page, :layout => :default %>

Upvotes: 1

Related Questions