Home > Ruby Rails > Passing parameters to a partial

Passing parameters to a partial

Hi,

This is just a quick post about how to pass parameters to rails partials. (As most of you all know, partials are lightweight than components) and personally I’m using it in my project as headers and footers.

But if we are to pass some parameters to the partial how to do that ?? its simple as this

render :partial => “<partial name>”, :locals => { :param1 => “value”}

<partial name> – name of your partial (Ex /partials/footer)

:params1 – parameter name

“value” – value

Its quick and simple 🙂


Advertisements
Categories: Ruby Rails Tags: , ,
  1. Shripad K
    June 20, 2010 at 3:55 pm

    Just a heads up:

    You can pass collections too..

    render :partial => “”, :locals => { collections => {:param1 => “value”, :param2 => “value2”, :param3 => “value3” } }

    Cheers 🙂

  2. Shripad K
    June 20, 2010 at 3:57 pm

    oops that should have been:

    render :partial => “”, :locals => { :collections => {:param1 => “value”, :param2 => “value2″, :param3 => “value3″ } }

  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: