Denny Mueller
Denny Mueller

Reputation: 3615

Split ruby on rails view correctly

playing around with rails and got a little problem with the layout.

I have a simple home mvc. Content of the home view is just

<h3>Home</h3>
<p>content</p>

I have my application view for overall design with some partials and so on.

              <section>
                <header>
                  <div class="pull-right">
                      <a class="btn btn-small">Edit</a>
                      <a class="btn btn-small">Blurm</a>
                  </div>
                  <h3>Head goes here</h3>
                </header>
                <%= yield %>
              </section>

Now I come to my main Part for displaying the different pages with yield. How should i split up the template? Should I put the complete application part to the home view to display the Heading in the right place? Or is there a possibilty to get the Heading different from the yield?

Any Suggestions?

P.S.: If someone have a nice tutorial or website for explaining How to structure and plan the views. A comment below would be nice.

best regards dennym

Upvotes: 1

Views: 455

Answers (2)

AlexBrand
AlexBrand

Reputation: 12419

I think that you are asking about using named yields.

From your structure, we add a yield named header

          <section>
            <header>
              <div class="pull-right">
                  <a class="btn btn-small">Edit</a>
                  <a class="btn btn-small">Blurm</a>
              </div>
              <h3><%= yield :header %></h3>
            </header>
            <%= yield %>
          </section>

And then we set the content for that named yield:

<% content_for :header do %>
    My header
<% end %>

<p> Rest of page ...</p>

Upvotes: 1

Dan Baker
Dan Baker

Reputation: 1827

If you are just trying to change you header periodically I would suggest either you have different layouts that have different headers which you could specify in your controller by layout :layout_name, or dynamically change header content using js.

Upvotes: 0

Related Questions