Hello, I want to be able to call a partial with and without a local. E.g.: 1 - <%= render :partial => "/contacts/phones/create", :locals => { :parent_form => contact_form, :phone => Phone.new} %> 2 - <%= render :partial => "/contacts/phones/create", :locals => { :parent_form => contact_form, :phone => Phone.new, :child_index => "111" } %> In my partial I have: <% if child_index -%> Do something <% else -%> Do something else <% end -%> The problem is that, when I don''t pass the local child_index, the partial don''t render and give me a error. What is the problem? Thanks, David Sousa -- Posted via http://www.ruby-forum.com/.
Hello... the solution: http://hackd.thrivesmarthq.com/how-to-make-a-rails-partial-with-optional-locals-parameters I''m still looking for a dryer way. Regards, David Sousa David Sousa wrote:> Hello, > > I want to be able to call a partial with and without a local. > E.g.: > 1 - <%= render :partial => "/contacts/phones/create", :locals => { > :parent_form => contact_form, :phone => Phone.new} %> > > 2 - <%= render :partial => "/contacts/phones/create", :locals => { > :parent_form => contact_form, :phone => Phone.new, :child_index => "111" > } %> > > In my partial I have: > > <% if child_index -%> > Do something > <% else -%> > Do something else > <% end -%> > > The problem is that, when I don''t pass the local child_index, the > partial don''t render and give me a error. What is the problem? > > Thanks, > David Sousa-- Posted via http://www.ruby-forum.com/.
what about using blank? On 17 jul, 00:06, David Sousa <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hello... > the solution:http://hackd.thrivesmarthq.com/how-to-make-a-rails-partial-with-optio... > > I''m still looking for a dryer way. > > Regards, > > David Sousa > > > > David Sousa wrote: > > Hello, > > > I want to be able to call a partial with and without a local. > > E.g.: > > 1 - <%= render :partial => "/contacts/phones/create", :locals => { > > :parent_form => contact_form, :phone => Phone.new} %> > > > 2 - <%= render :partial => "/contacts/phones/create", :locals => { > > :parent_form => contact_form, :phone => Phone.new, :child_index => "111" > > } %> > > > In my partial I have: > > > <% if child_index -%> > > Do something > > <% else -%> > > Do something else > > <% end -%> > > > The problem is that, when I don''t pass the local child_index, the > > partial don''t render and give me a error. What is the problem? > > > Thanks, > > David Sousa > > -- > Posted viahttp://www.ruby-forum.com/.
what about using blank? On 17 jul, 00:06, David Sousa <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hello... > the solution:http://hackd.thrivesmarthq.com/how-to-make-a-rails-partial-with-optio... > > I''m still looking for a dryer way. > > Regards, > > David Sousa > > > > David Sousa wrote: > > Hello, > > > I want to be able to call a partial with and without a local. > > E.g.: > > 1 - <%= render :partial => "/contacts/phones/create", :locals => { > > :parent_form => contact_form, :phone => Phone.new} %> > > > 2 - <%= render :partial => "/contacts/phones/create", :locals => { > > :parent_form => contact_form, :phone => Phone.new, :child_index => "111" > > } %> > > > In my partial I have: > > > <% if child_index -%> > > Do something > > <% else -%> > > Do something else > > <% end -%> > > > The problem is that, when I don''t pass the local child_index, the > > partial don''t render and give me a error. What is the problem? > > > Thanks, > > David Sousa > > -- > Posted viahttp://www.ruby-forum.com/.
what about using <% unless child_index.blank? -%> Do something <% else -%> Do something else <% end -%> Thank you Rodrigo Dominguez David Sousa wrote:> Hello, > > I want to be able to call a partial with and without a local. > E.g.: > 1 - <%= render :partial => "/contacts/phones/create", :locals => { > :parent_form => contact_form, :phone => Phone.new} %> > > 2 - <%= render :partial => "/contacts/phones/create", :locals => { > :parent_form => contact_form, :phone => Phone.new, :child_index => "111" > } %> > > In my partial I have: > > <% if child_index -%> > Do something > <% else -%> > Do something else > <% end -%> > > The problem is that, when I don''t pass the local child_index, the > partial don''t render and give me a error. What is the problem? > > Thanks, > David Sousa-- Posted via http://www.ruby-forum.com/.
Sorry just replied to you directly and not to the group.. Use the defined? method like... <% if defined?(child_index) && child_index %> -Evan Worley On Jul 16, 9:46 pm, Rodrigo Dominguez <rails-mailing-l...@andreas- s.net> wrote:> what about using > > <% unless child_index.blank? -%> > Do something > <% else -%> > Do something else > <% end -%> > > Thank you > > Rodrigo Dominguez > > > > David Sousa wrote: > > Hello, > > > I want to be able to call a partial with and without a local. > > E.g.: > > 1 - <%= render :partial => "/contacts/phones/create", :locals => { > > :parent_form => contact_form, :phone => Phone.new} %> > > > 2 - <%= render :partial => "/contacts/phones/create", :locals => { > > :parent_form => contact_form, :phone => Phone.new, :child_index => "111" > > } %> > > > In my partial I have: > > > <% if child_index -%> > > Do something > > <% else -%> > > Do something else > > <% end -%> > > > The problem is that, when I don''t pass the local child_index, the > > partial don''t render and give me a error. What is the problem? > > > Thanks, > > David Sousa > > -- > Posted viahttp://www.ruby-forum.com/.