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

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: