Sarahshuffle
Sarahshuffle

Reputation: 182

Is it possible to load + render an html.erb file within another html.erb file?

Is it possible to render another file, such as my show.html.erb, within my main.html.erb file?

"show.html.erb" belongs to a calendar controller. "main.html.erb" belongs to a Pages controller.

I want to do this because:

  1. I need to access some specific data from within the calendar in the database.
  2. I don't want my calendar to take up an entire view frame. I want it to be small and be integrated into the main page.

How would I go about doing this? Is it a silly idea?

Upvotes: 0

Views: 3427

Answers (1)

Leo Brito
Leo Brito

Reputation: 2051

Yes, with partials. So if you want to render _my_view.html.erb within some other view, you should insert the following:

<%= render partial: "my_view", locals: { myvar: @val } %>

Where you can pass variables to the partial through the locals hash.

Upvotes: 4

Related Questions