I''m porting an old site of mine into Rails and I''m running
into some
duplication that could / needs to be weeded out. For each of my
actions, I have to wrap the view content in the following HTML:
<div class="box">
<img src="/images/content-top2.png" class="border"
/>
<div class="visible">
# content inserted here
</div>
<img src="/images/content-bottom2.png" class="border"
/>
</div>
Unfortunately, I can''t add this snippet into the controller''s
layout,
as each posts (think blog), needs to be wrapped in this html.
The existing, non-Rails implementation can be found at http://
www.hsgamedev.org and should be a good visual aide.
Any suggestions?
~ ryan ~
On Tue, 2005-12-27 at 17:04 -0500, J. Ryan Sobol wrote:> I''m porting an old site of mine into Rails and I''m running into some > duplication that could / needs to be weeded out. For each of my > actions, I have to wrap the view content in the following HTML: > > <div class="box"> > <img src="/images/content-top2.png" class="border" /> > <div class="visible"> > > # content inserted here > > </div> > <img src="/images/content-bottom2.png" class="border" /> > </div> > > Unfortunately, I can''t add this snippet into the controller''s layout, > as each posts (think blog), needs to be wrapped in this html. > > The existing, non-Rails implementation can be found at http:// > www.hsgamedev.org and should be a good visual aide. > > Any suggestions? > > ~ ryan ~Ryan, You want partials. create a file called /app/views/controller/action/_box.rhtml It will look like this: <div class="box"> <img src="/images/content-top2.png" class="border" /> <div class="visible"> <%= content %> </div> <img src="/images/content-bottom2.png" class="border" /> </div> You can now render it like this in your other views: <%= render :partial => ''box'', :locals => { :content => @foo } %> If you''re wanting to reuse this partial for many things, I believe you can nest it, so replace @foo with another render :partial call, with partials named _blog.rhtml, _comment.rhtml, or whatever. - Jamie
Why wouldn''t adding the code below to the controller layout work?
For example, assuming a controller named "blog", you could have the
following in app>views>layouts>blog.rhtml:
<div class="box">
<img src="/images/content-top2.png" class="border"
/>
<div class="visible">
<%= @content_for_layout %>
</div>
<img src="/images/content-bottom2.png" class="border"
/>
</div>
The "<%= @content_for_layout %>" would include whatever content
each
view produced.
Sorry if I misunderstood you.
Thanks.
Steven
On Dec 27, 2005, at 4:04 PM, J. Ryan Sobol wrote:
> I''m porting an old site of mine into Rails and I''m
running into
> some duplication that could / needs to be weeded out. For each of
> my actions, I have to wrap the view content in the following HTML:
>
> <div class="box">
> <img src="/images/content-top2.png" class="border"
/>
> <div class="visible">
>
> # content inserted here
>
> </div>
> <img src="/images/content-bottom2.png"
class="border" />
> </div>
>
> Unfortunately, I can''t add this snippet into the
controller''s
> layout, as each posts (think blog), needs to be wrapped in this html.
>
> The existing, non-Rails implementation can be found at http://
> www.hsgamedev.org and should be a good visual aide.
>
> Any suggestions?
>
> ~ ryan ~
>
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
Jamie, I wasn''t aware of the ability to nest render(:partial => ...) calls. I''ll re-read the docs on the render method. ~ ryan ~ On Dec 27, 2005, at 5:10 PM, Jamie Macey wrote:> Ryan, > > You want partials. create a file > called /app/views/controller/action/_box.rhtml > > It will look like this: > <div class="box"> > <img src="/images/content-top2.png" class="border" /> > <div class="visible"> > <%= content %> > </div> > <img src="/images/content-bottom2.png" class="border" /> > </div> > > > You can now render it like this in your other views: > > <%= render :partial => ''box'', :locals => { :content => @foo } %> > > If you''re wanting to reuse this partial for many things, I believe you > can nest it, so replace @foo with another render :partial call, with > partials named _blog.rhtml, _comment.rhtml, or whatever. > > - Jamie_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Steven, Don''t be sorry. :) I''m fairly certain this wouldn''t work because I need to, potentially, wrap multiple blog-like posts per action. Take a look at the source code for the site I posted in my first message to *see* what I mean. ~ ryan ~ On Dec 27, 2005, at 5:16 PM, Steven Smith wrote:> Why wouldn''t adding the code below to the controller layout work? > For example, assuming a controller named "blog", you could have the > following in app>views>layouts>blog.rhtml: > > <div class="box"> > <img src="/images/content-top2.png" class="border" /> > <div class="visible"> > > <%= @content_for_layout %> > > </div> > <img src="/images/content-bottom2.png" class="border" /> > </div> > > The "<%= @content_for_layout %>" would include whatever content > each view produced. > > Sorry if I misunderstood you. > > Thanks. > Steven > > On Dec 27, 2005, at 4:04 PM, J. Ryan Sobol wrote: > >> I''m porting an old site of mine into Rails and I''m running into >> some duplication that could / needs to be weeded out. For each of >> my actions, I have to wrap the view content in the following HTML: >> >> <div class="box"> >> <img src="/images/content-top2.png" class="border" /> >> <div class="visible"> >> >> # content inserted here >> >> </div> >> <img src="/images/content-bottom2.png" class="border" /> >> </div> >> >> Unfortunately, I can''t add this snippet into the controller''s >> layout, as each posts (think blog), needs to be wrapped in this >> html. >> >> The existing, non-Rails implementation can be found at http:// >> www.hsgamedev.org and should be a good visual aide. >> >> Any suggestions? >> >> ~ ryan ~ >> >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Jamie,
<%= render(:partial => ''box'', :locals => { :content
=> render
(:partial => ''post'') }) %> # works
<%= render(:partial => ''box'', :locals => { :content
=> "<%= link_to
''Back'', :action => ''list'' %>" } )
%> # doesn''t work
I''d like to try to avoid creating a partial template file for small,
one-liners like the string in the second example. Any thoughts?
~ ryan ~
On Dec 27, 2005, at 5:10 PM, Jamie Macey wrote:
> On Tue, 2005-12-27 at 17:04 -0500, J. Ryan Sobol wrote:
>> I''m porting an old site of mine into Rails and I''m
running into some
>> duplication that could / needs to be weeded out. For each of my
>> actions, I have to wrap the view content in the following HTML:
>>
>> <div class="box">
>> <img src="/images/content-top2.png"
class="border" />
>> <div class="visible">
>>
>> # content inserted here
>>
>> </div>
>> <img src="/images/content-bottom2.png"
class="border" />
>> </div>
>>
>> Unfortunately, I can''t add this snippet into the
controller''s layout,
>> as each posts (think blog), needs to be wrapped in this html.
>>
>> The existing, non-Rails implementation can be found at http://
>> www.hsgamedev.org and should be a good visual aide.
>>
>> Any suggestions?
>>
>> ~ ryan ~
>
> Ryan,
>
> You want partials. create a file
> called /app/views/controller/action/_box.rhtml
>
> It will look like this:
> <div class="box">
> <img src="/images/content-top2.png"
class="border" />
> <div class="visible">
> <%= content %>
> </div>
> <img src="/images/content-bottom2.png"
class="border" />
> </div>
>
>
> You can now render it like this in your other views:
>
> <%= render :partial => ''box'', :locals => {
:content => @foo } %>
>
> If you''re wanting to reuse this partial for many things, I believe
you
> can nest it, so replace @foo with another render :partial call, with
> partials named _blog.rhtml, _comment.rhtml, or whatever.
>
> - Jamie
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
Nevermind, I''m an idiot.
<%= render(:partial => ''box'', :locals => { :content
=> link_to
(''Back'', :action => ''list'') } ) %>
~ ryan ~
On 12/27/05, J. Ryan Sobol <ryansobol@gmail.com> wrote:> Jamie, > > <%= render(:partial => 'box', :locals => { :content => render > (:partial => 'post') }) %> # works > > <%= render(:partial => 'box', :locals => { :content => "<%= link_to > 'Back', :action => 'list' %>" } ) %> # doesn't work > > I'd like to try to avoid creating a partial template file for small, > one-liners like the string in the second example. Any thoughts? > > ~ ryan ~ > > > On Dec 27, 2005, at 5:10 PM, Jamie Macey wrote: > > > On Tue, 2005-12-27 at 17:04 -0500, J. Ryan Sobol wrote: > >> I'm porting an old site of mine into Rails and I'm running into some > >> duplication that could / needs to be weeded out. For each of my > >> actions, I have to wrap the view content in the following HTML: > >> > >> <div class="box"> > >> <img src="/images/content-top2.png" class="border" /> > >> <div class="visible"> > >> > >> # content inserted here > >> > >> </div> > >> <img src="/images/content-bottom2.png" class="border" /> > >> </div> > >> > >> Unfortunately, I can't add this snippet into the controller's layout, > >> as each posts (think blog), needs to be wrapped in this html. > >> > >> The existing, non-Rails implementation can be found at http:// > >> www.hsgamedev.org and should be a good visual aide. > >> > >> Any suggestions? > >> > >> ~ ryan ~ > > > > Ryan, > > > > You want partials. create a file > > called /app/views/controller/action/_box.rhtml > > > > It will look like this: > > <div class="box"> > > <img src="/images/content-top2.png" class="border" /> > > <div class="visible"> > > <%= content %> > > </div> > > <img src="/images/content-bottom2.png" class="border" /> > > </div> > > > > > > You can now render it like this in your other views: > > > > <%= render :partial => 'box', :locals => { :content => @foo } %> > > > > If you're wanting to reuse this partial for many things, I believe you > > can nest it, so replace @foo with another render :partial call, with > > partials named _blog.rhtml, _comment.rhtml, or whatever. > > > > - Jamie > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >Not sure if the overall idea is the most elegant way to go, but <%= render(:partial => 'box', :locals => { :content => "<%= link_to 'Back', :action => 'list' %>" } ) %> # doesn't work <%= render(:partial => 'box', :locals => { :content => "#{link_to 'Back', :action => 'list'}" } ) %> # should work -- Kyle Maxwell Chief Technologist E Factor Media // FN Interactive kyle@efactormedia.com 1-866-263-3261 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails