So far, it’s RoR

Ruby on Rails, PostgreSQL, SVN, etc….

Passing parameters to partials

Posted by Chirag Patel on September 12, 2007

Partial basics

Some different things about passing parameters to partials

  1. Basics of passing parameters (i.e. locals) into partials – Why are parameters for partials (locals) passed differently than params for urls?!? Don’t know, but basically use the locals hash in both the render call and use the name of the local in the partial itself. This link also shows how to explicitly check for local parameter in case it’s nil
  2. Making a partial use optional parameters – Basically, set the parameter to nil inside the partial (e.g. title = nil unless defined?(title))
  3. Why passing locals in partials is preferred over @variables – Partials can see the @variables of its parent view, but instead pass the variables as parameters for clarity in complex code bases

Debugging partials

  1. be sure to look at console log (and/or development log), it will show the parameters being passed

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>