Duane Johnson
2005-Apr-07 17:50 UTC
How do I print within a ruby block (in a view) without using angle brackets?
I am used to writing code such as this:
<% for @project in @unallocated_projects %>
<%= render_partial "project_row" %>
<% end %>
But is there a way to reduce the number of open/close brackets? I''d
like to do something like this:
<% for @project in @unallocated_projects
print render_partial("project_row")
end %>
How do I do this?
Thanks,
Duane Johnson
(canadaduane)
Joe Van Dyk
2005-Apr-07 17:54 UTC
Re: How do I print within a ruby block (in a view) without using angle brackets?
Ooh, I''d like to know that too. On Apr 7, 2005 10:50 AM, Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am used to writing code such as this: > > <% for @project in @unallocated_projects %> > <%= render_partial "project_row" %> > <% end %> > > But is there a way to reduce the number of open/close brackets? I''d > like to do something like this: > > <% for @project in @unallocated_projects > print render_partial("project_row") > end %> > > How do I do this? > > Thanks, > Duane Johnson > (canadaduane) > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Jeremy Kemper
2005-Apr-07 18:09 UTC
Re: How do I print within a ruby block (in a view) without using angle brackets?
Joe Van Dyk wrote:> Ooh, I''d like to know that too. > > On Apr 7, 2005 10:50 AM, Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >>I am used to writing code such as this: >> >><% for @project in @unallocated_projects %> >> <%= render_partial "project_row" %> >><% end %> >> >>But is there a way to reduce the number of open/close brackets? I''d >>like to do something like this: >> >><% for @project in @unallocated_projects >> print render_partial("project_row") >>end %> >> >>How do I do this?There''s an erb mode that allows a single leading % % for p in q Who''s the best? <%= p %>''s the best! % end But you''ll need to do some ActionView sleuthing to enable it. jeremy
Juraci Krohling Costa
2005-Apr-07 18:20 UTC
Re: How do I print within a ruby block (in a view) without using angle brackets?
wow =) this one is pretty!!! On Apr 7, 2005 3:09 PM, Jeremy Kemper <jeremy-w7CzD/W5Ocjk1uMJSBkQmQ@public.gmane.org> wrote:> > Joe Van Dyk wrote: > > Ooh, I''d like to know that too. > > > > On Apr 7, 2005 10:50 AM, Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > >>I am used to writing code such as this: > >> > >><% for @project in @unallocated_projects %> > >> <%= render_partial "project_row" %> > >><% end %> > >> > >>But is there a way to reduce the number of open/close brackets? I''d > >>like to do something like this: > >> > >><% for @project in @unallocated_projects > >> print render_partial("project_row") > >>end %> > >> > >>How do I do this? > > There''s an erb mode that allows a single leading % > > % for p in q > Who''s the best? <%= p %>''s the best! > % end > > But you''ll need to do some ActionView sleuthing to enable it. > > jeremy > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- juraci krohling costa http://jkcosta.info _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Shalev NessAiver
2005-Apr-07 19:07 UTC
Re: How do I print within a ruby block (in a view) without using angle brackets?
Ya know, I''ve never seen it done in erb, but wouldn''t you just do <%= render_collection_of_partials "project_row", @unallocated_projects %> anyway? -Shalev On Apr 7, 2005 1:50 PM, Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am used to writing code such as this: > > <% for @project in @unallocated_projects %> > <%= render_partial "project_row" %> > <% end %> > > But is there a way to reduce the number of open/close brackets? I''d > like to do something like this: > > <% for @project in @unallocated_projects > print render_partial("project_row") > end %> > > How do I do this? > > Thanks, > Duane Johnson > (canadaduane) > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Ben Schumacher
2005-Apr-07 19:42 UTC
Re: How do I print within a ruby block (in a view) without using angle brackets?
You could do this:
<%= @unallocated_projects.collect { |project| render_partial
''project_row'', project }.join %>
Cheers,
Ben
On Apr 7, 2005 11:50 AM, Duane Johnson
<duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I am used to writing code such as this:
>
> <% for @project in @unallocated_projects %>
> <%= render_partial "project_row" %>
> <% end %>
>
> But is there a way to reduce the number of open/close brackets?
I''d
> like to do something like this:
>
> <% for @project in @unallocated_projects
> print render_partial("project_row")
> end %>
>
> How do I do this?
>
> Thanks,
> Duane Johnson
> (canadaduane)
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
Jordan Running
2005-Apr-07 20:37 UTC
Re: How do I print within a ruby block (in a view) without using angle brackets?
> There''s an erb mode that allows a single leading % > > % for p in q > Who''s the best? <%= p %>''s the best! > % end > > But you''ll need to do some ActionView sleuthing to enable it.This is also mentioned here: http://redhanded.hobix.com/inspect/cleanerErbSyntax.html ..but there are no details on enabling it. I would love to know how this can be enabled. Please, anybody?
Juraci Krohling Costa
2005-Apr-07 20:57 UTC
Re: Re: How do I print within a ruby block (in a view) without using angle brackets?
Hi,
Here it is :-)
<excerpt url="
http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html">
new(str, safe_level=nil, trim_mode=nil, eoutvar=''_erbout'')
<http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html#M000002>
Constructs a new
ERB<http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html>object
with the template specified in
*str*.
An ERB
<http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html>object
works by building a chunk of Ruby code that will output the completed
template when run. If *safe_level* is set to a non-nil value,
ERB<http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html>code
will be run in a separate thread with
*$SAFE* set to the provided level.
If *trim_mode* is passed a String containing one or more of the following
modifiers,
ERB<http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html>will
adjust its code generation as listed:
% enables Ruby code processing for lines beginning with %
<> omit newline for lines starting with <% and ending in %>
> omit newline for lines ending in %>
*eoutvar* can be used to set the name of the variable
ERB<http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html>will
build up its output in. This is useful when you need to run multiple
ERB
<http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html>templates
through the same binding and/or when you want to control where
output ends up. Pass the name of the variable to be used inside a String.
</excerpt>
regards,
juca
On Apr 7, 2005 5:37 PM, Jordan Running
<jrunning-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> > There''s an erb mode that allows a single leading %
> >
> > % for p in q
> > Who''s the best? <%= p %>''s the best!
> > % end
> >
> > But you''ll need to do some ActionView sleuthing to enable it.
>
> This is also mentioned here:
> http://redhanded.hobix.com/inspect/cleanerErbSyntax.html
>
> ..but there are no details on enabling it. I would love to know how this
> can be
> enabled. Please, anybody?
>
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
juraci krohling costa
http://jkcosta.info
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
Gavin Sinclair
2005-Apr-07 22:22 UTC
Re: How do I print within a ruby block (in a view) without using angle brackets?
On Friday, April 8, 2005, 3:50:54 AM, Duane wrote:> I am used to writing code such as this:> <% for @project in @unallocated_projects %> > <%= render_partial "project_row" %> > <% end %>> But is there a way to reduce the number of open/close brackets? I''d > like to do something like this:> <% for @project in @unallocated_projects > print render_partial("project_row") > end %>> How do I do this?Well..... Your Rails view is based on ERb, and ERb has an initialisation option that could help reduce bracket clutter. See http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html#M000002 In the Rails code I find two instances of this method, both of the form: ERB.new(template, nil, ''-'') I have no idea what the ''-'' does, but if it were changed to ''-%'' or ''%'', you could do the following in your view: % for @project in @unallocated_projects %= render_partial "project_row" % end That''s a lot less bracket clutter :) I''d really like to see this approach adopted. Cheers, Gavin