neanderslob
neanderslob

Reputation: 2693

Embedding a rails view within a view

Rails noob here. I'm attempting to create create single-page scrolling site similar to this ...but, you know, not nearly as attractive :-)

Anyway, I've got my javascript working however I've developed much of the content (contact form, about us page etc etc) in different views which are hanging out in various html.erb files. Rather than cut and paste the contents of each into a single home.html.erb, I was wondering if there was a clean way to just embed the content from each view into my homepage view. Something like this:

<h1>My awesome homepage!</h1>
<div>
    <div id="about">
    <%= put_page_here page=about_us %>
    </div>
    <div id="our_product">
    <%= put_page_here page=about_us %>
    </div>
    <div id="contact">
    <%= put_page_here page=contact %>
    </div>
</div>

If you would recommend going about this entirely differently, please let me know.

Many thanks in advance!

Upvotes: 1

Views: 70

Answers (1)

Undo
Undo

Reputation: 25687

This should work:

<%= render partial:"shared/contact_us", locals:{variable:value} %>

Note that it will look for a view in app/views/shared/_contact_us.html.erb - notice the _ before the view. Pass the variables the view needs in through locals. More information on passing variables around here.

Upvotes: 1

Related Questions