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. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Brent <wejrowski@...> writes:> > 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. >Placing <%= yield %> in your partial will determine where blocks are rendered: #app/views/shared/partialname.html.erb <h1>This is a partial heading</a> <%= yield %> Should result in: <h1>This is a partial heading</a> Misc code / text -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
That''s exactly what I tried. I''ve tried multiple variations too but I can''t seem to get it. On Jul 28, 4:27 pm, Andrew Skegg <andrewsk...-BUHhN+a2lJ4@public.gmane.org> wrote:> Brent <wejrowski@...> writes: > > > 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. > > Placing <%= yield %> in your partial will determine where blocks are rendered: > > #app/views/shared/partialname.html.erb > <h1>This is a partial heading</a> > <%= yield %> > > Should result in: > > <h1>This is a partial heading</a> > Misc code / text-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
This works for me: views/layouts/application.html.erb: <!DOCTYPE html> <html> <head> <title><%= @title %></title> <%= csrf_meta_tag %> </head> <body> <%= yield %> </body> </html> views/users/new.html.erb: <h1>Users#new</h1> <p>Find me in app/views/users/new.html.erb</p> <%= render :layout => ''shared/awesome'', :locals => {:greeting => ''hello''} do %> <div>world</div> <% end %> views/shared/_awesome.html.erb: <div><%= greeting %></div> <%= yield %> http://localhost:3000/users/new View Source: <!DOCTYPE html> <html> <head> <title>Sign up</title> <meta name="csrf-param" content="authenticity_token"/> <meta name="csrf-token" content="3S4d6FpN0hkzvwCHEbNG/OR34UBwqOTlhDtwL5VIXd4="/> </head> <body> <h1>Users#new</h1> <p>Find me in app/views/users/new.html.erb</p> <div>hello</div> <div>world</div> </body> </html> -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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? ^ On Jul 29, 10:37 am, 7stud -- <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> This works for me: > > views/layouts/application.html.erb: > > <!DOCTYPE html> > <html> > <head> > <title><%= @title %></title> > <%= csrf_meta_tag %> > </head> > <body> > > <%= yield %> > > </body> > </html> > > views/users/new.html.erb: > > <h1>Users#new</h1> > <p>Find me in app/views/users/new.html.erb</p> > > <%= render :layout => ''shared/awesome'', :locals => {:greeting => > ''hello''} do %> > <div>world</div> > <% end %> > > views/shared/_awesome.html.erb: > > <div><%= greeting %></div> > <%= yield %> > > http://localhost:3000/users/new > View Source: > > <!DOCTYPE html> > <html> > <head> > <title>Sign up</title> > <meta name="csrf-param" content="authenticity_token"/> > <meta name="csrf-token" > content="3S4d6FpN0hkzvwCHEbNG/OR34UBwqOTlhDtwL5VIXd4="/> > </head> > <body> > > <h1>Users#new</h1> > <p>Find me in app/views/users/new.html.erb</p> > <div>hello</div> > > <div>world</div> > > </body> > </html> > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.