Passing parameters to partials
Posted by Chirag Patel on September 12, 2007
Some different things about passing parameters to partials
- Basics of passing parameters (i.e. locals) into partials – Why are parameters for partials (
locals) passed differently thanparamsfor urls?!? Don’t know, but basically use thelocalshash in both therendercall 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’snil - Making a partial use optional parameters – Basically, set the parameter to
nilinside the partial (e.g.title = nil unless defined?(title)) - Why passing locals in partials is preferred over @variables – Partials can see the
@variablesof its parent view, but instead pass the variables as parameters for clarity in complex code bases
Debugging partials
- be sure to look at console log (and/or development log), it will show the parameters being passed
