How can I capture the block that I pass through a partial. I want to
be able to do something like:
<%= render ‘shared/partialname’ do %>
Misc code / text
<% end %>
Then I want to display that block at a specific place in that partial.
I could do this if I created a method. But I want to know how it works
with partials.
brent
July 29, 2011, 1:29am
2
Brent <wejrowski@…> writes:
with partials.
Placing <%= yield %> in your partial will determine where blocks are
rendered:
#app /views/shared/partialname.html.erb
This is a partial heading
<%= yield %>
Should result in:
This is a partial heading
Misc code / text
brent
July 29, 2011, 5:59pm
3
That’s exactly what I tried. I’ve tried multiple variations too but I
can’t seem to get it.
brent
August 1, 2011, 8:13pm
4
Darn you know what it was… I was doing render ‘partialname’…
instead of render :layout=>‘partialname’
Thanks! BTW anyone know what the difference is there? ^
brent
July 29, 2011, 7:37pm
5
This works for me in rails 3.0.9:
views/layouts/application.html.erb:
<%= @title %>
<%= csrf_meta_tag %>
<%= yield %>
views/users/new.html.erb:
Users#new
Find me in app/views/users/new.html.erb
<%= render :layout => ‘shared/awesome’,
:locals => {:greeting => ‘hello’} do %>
world
<% end %>
views/shared/_awesome.html.erb:
<%= greeting %>
<%= yield %>
controllers/user_controller.rb:
class UsersController < ApplicationController
def new
@title = “Sign up”
end
end
http://localhost:3000/users/new
View Source:
Sign up
Users#new
Find me in app/views/users/new.html.erb
hello
world
brent
August 1, 2011, 11:19pm
6
Brent wrote in post #1014240:
Darn you know what it was… I was doing render ‘partialname’…
instead of render :layout=>‘partialname’
Yah. That was the point of my post.