Just a quick question. How can I decide in a sub template whether I have a parameter given or not. I''ve created an applet container partial and if I pass dimensions template should include "width=''...'' height=''...''" but if not it should be skipped. Anyway how can I access the array of local_assigns from the template? Thanks, Gábor
On 2005.05.03., at 8:50, Sebestyén Gábor wrote:> Just a quick question. How can I decide in a sub template whether I > have a parameter given or not. I''ve created an applet container > partial and if I pass dimensions template should include > "width=''...'' height=''...''" but if not it should be skipped. Anyway > how can I access the array of local_assigns from the template? >Ok, I have it! In sub template aKey can be optional in this form: <% if @assigns.has_key? ''aKey'' %><%= aKey %><% end %> But it would have been nice to see it documented. Gábor
On Tuesday, May 3, 2005, 4:50:26 PM, Sebestyén wrote:> Just a quick question. How can I decide in a sub template whether I > have a parameter given or not. I''ve created an applet container > partial and if I pass dimensions template should include "width=''...'' > height=''...''" but if not it should be skipped. Anyway how can I > access the array of local_assigns from the template?Say you want 30 to be the default values for width and height: <% width = 30 unless defined? :width %> <% height = 30 unless defined? :height %> I like that better than poking around with @assigns. Partials are supposed to work with local variables, which the above code acknowledges. @assigns reeks of implementation detail, not a feature. Gavin
Wouldn''t it be better to call render_partial in a ruby method, and define default option values there? e.g.: def render_applet (width = 30, height = 30) render_partial... end Which you could then call inline: <%= render_applet %> Or with a width and height: <%= render_applet(40, 75) %> That way you keep your rhtml template as free of inline ruby code as possible. I dislike having to mix XHTML, JavaScript and inline-Ruby too much! sam On 5/3/05, Gavin Sinclair <gsinclair-81uBx+iSpXA0n/F98K4Iww@public.gmane.org> wrote:> On Tuesday, May 3, 2005, 4:50:26 PM, Sebestyén wrote: > > > Just a quick question. How can I decide in a sub template whether I > > have a parameter given or not. I''ve created an applet container > > partial and if I pass dimensions template should include "width=''...'' > > height=''...''" but if not it should be skipped. Anyway how can I > > access the array of local_assigns from the template? > > Say you want 30 to be the default values for width and height: > > <% width = 30 unless defined? :width %> > <% height = 30 unless defined? :height %> > > I like that better than poking around with @assigns. Partials are > supposed to work with local variables, which the above code > acknowledges. @assigns reeks of implementation detail, not a feature. > > Gavin > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- sam http://www.magpiebrain.com/
On 2005.05.03., at 17:42, Sam Newman wrote:> def render_applet (width = 30, height = 30) > render_partial... > end >Seems ok but there are more optional parameters like apple PARAMs they can be more ore none. So I cannot avoid putting some optionality codes into rhtml. Gábor _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails