Take the 2-minute tour ×

I've seen a couple questions on this but haven't been able to solve it...

I'm trying to pass a parameter while rendering a partial (similar to domainname.com/memory_books/new?fbookupload=yes)...right now I use this line:

<%= render :partial => '/memory_books/new', :fbookupload => "yes" %>

and in the partial...I have tried to get the content of fbookupload by using:

<%= fbookupload %>

which gives an "undefined local variable" error and

<%= params.inspect %>

which does not show fbookupload as a parameter.

How can I have the partial pass along the parameter :fbookupload?

Thank you.


Could it have anything to do with the fact that I'm rendering this within a render?

i.e. the page (/fbookphotos/show) that has


is being rendered by another page with (posts/show) via:

<%= render :partial => '/fbookphotos/show' %>

so I'm remember this within a render...

share|improve this question

4 Answers 4

up vote 9 down vote accepted

try this:

<%= render :partial => '/memory_books/new', :locals => {:fbookupload => "yes"} %>
share|improve this answer
tried that too and same problem... –  user749798 Jul 1 '12 at 16:35
I think your code is ok, is there something wrong with your partial? –  Someth Victory Jul 1 '12 at 16:51
or there maybe something wrong with the path of your partial –  Someth Victory Jul 1 '12 at 16:53
the rest of the partial loads. could it have something to do with my partial loading within a partial? –  user749798 Jul 1 '12 at 16:54
got it, was referring to the partial elsewhere without the local variable and thus was messing up the rendering. thanks! –  user749798 Jul 1 '12 at 17:11

Taking it out of the comments for posterity. This syntax is correct:

render '/memory_books/new', fbookupload: "yes"

But if there is a reference to rendering the same partial without specifying the local variables, e.g.

render '/memory_books/new'

then fbookupload variable becomes unavailable. The same applies to multiple local variables, e.g.

render 'my_partial', var1: 'qq', var2: 'qqq'

will work if only occurs once. But if there is something like that somewhere else in the code

render 'my_partial', var1: 'qq'

then the var2 will become unavailable. Go figure ...

share|improve this answer

To do it your way:

In the main view:

<% fbookupload = "yes" %>
<%= render :partial => '/memory_books/new', :locals => {:fbookupload => fbookupload} %>

And in the partial:

<%= fbookupload %>

2nd option:

Ideally in the controller, otherwise in the view, define an instance variable: @fbookupload = "yes". Then it is available everywhere. The partial will then be : <%= @fbookupload %>

share|improve this answer
hmmm...not working either –  user749798 Jul 1 '12 at 16:47
Both of these will work; just tested. –  Teemu Leisti Jun 25 '13 at 12:07

Params is just request parameter, so if u want to pass it in params u have to add it to your url ?fbookupload=yes or assign it params[:fbookupload] = "yes", but i don't think that is a good idea.

But if u need to use params[:fbookupload]', u can replace it withparams[:fbookupload] || fbookupload', and pass fbookupload in locals hash for partial.

share|improve this answer
how would i add it to the url in a render? when i do <%= render :partial => '/memory_books/new?fbookupload=yes' %>, I get a "Missing partial" error –  user749798 Jul 1 '12 at 16:53
not in a partial, but in your browser url...but is not a good way to do, don't use params in partials, use local vars –  Yuri Barbashov Jul 1 '12 at 17:01
ok, not sure i get what the suggestion is then. –  user749798 Jul 1 '12 at 17:03
@Yuri Barbashov: You are confusing two things: URL parameters given to a view, and parameters given to a partial. Depending on the value of incoming URL parameters, different views and/or partials might be displayed, but that is determined after a controller parses the URL parameters. I suppose that one could use incoming URL parameters to conditionally redirect to a different view, and possibly use URL parameters in this redirect (actually, I don't even know if the latter is possible), but that's not really what the redirect is for, and strikes me as Not A Good Thing. –  Teemu Leisti Jun 25 '13 at 12:11
@TeemuLeisti I am not confusing two things: params in partials contains url parameters. If you look at the question you will see that he tried to inspect `params', so i showed how he can achieve that by assigning params value and told that this is not а good thing. –  Yuri Barbashov Jun 26 '13 at 9:41

Your Answer


