# Passing values to a Partial

**URL:** <https://www.ruby-forum.com/t/passing-values-to-a-partial/56411>\
**Category:** Rails\
**Created:** [March 31, 2006, 1:07am UTC](https://www.ruby-forum.com/t/passing-values-to-a-partial/56411 "2006-03-31T01:07:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kentbarber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e68b1a/32.png) [@kentbarber](https://www.ruby-forum.com/u/kentbarber)\
**Post date:** [March 31, 2006, 1:07am UTC](https://www.ruby-forum.com/t/passing-values-to-a-partial/56411/1 "2006-03-31T01:07:40Z")

</div>

Hi,

I cannot seem to find out how to pass in a value to a partial. Can  
anyone help me?

What I am doing(in the code below) is calling a function in my  
controller called setobject. This function just redraws the partial. I  
want to be able to change the value @objectname, redraw my partial and  
have it be able to use that value. The first the page is drawn it works,  
but when i call setobject it says that @objectname is null in my partial  
and it throws an error.

Code follows.

In my index.rhtml I have the following:  
\<%= render :partial =\> “properties” %\>

with some other code later on in the file  
\<%= drop\_receiving\_element “dcwindow”,  
:update =\> “items”, :url =\> { :action =\> “setobject” },  
:accept =\> “products”, :hoverclass =\> “cart-active”,  
:loading =\> “Element.show(‘indicator’)”,  
:complete =\>  
“Element.hide(‘indicator’);additem(element.alt,element.id);”  
%\>

In \_properties.rhtml I have:  
\<%  
command = @objectname  
%\>  
Which I then use later on.

In my controller file I have:  
def index  
@objectname = “Plane”  
end  
def setobject  
render :partial =\> “properties”  
end

Thank in advance!  
Kent

---

<div class="post-metadata">

**Author:** ![kentbarber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e68b1a/32.png) [@kentbarber](https://www.ruby-forum.com/u/kentbarber)\
**Post date:** [March 31, 2006, 1:45am UTC](https://www.ruby-forum.com/t/passing-values-to-a-partial/56411/2 "2006-03-31T01:45:25Z")

</div>

Here are some details about render():

> **[ActionController::Base](https://api.rubyonrails.org/classes/ActionController/Base.html#M000205)**
>
> Action Controllers are the core of a web request in Rails. They are made up of one or more actions that are executed on request and then either it renders a template or redirects to another action.

Specifically, the Rendering Partials section.

# Renders the same partial but also makes a local variable available

to it  
render :partial =\> “win”, :locals =\> { :name =\> “david” }

if the following change in the controller doesn’t work

> render :partial =\> “properties”, :locals =\> {:@objectname =\>  
> @objectname}  
> you might have to do  
> render :partial =\> “properties”, :locals =\> {:objectname =\>  
> @objectname}  
> and in \_properties.rhtml change  
> \<%  
> command = @objectname  
> %\>  
> to  
> \<%  
> command = @objectname || objectname  
> %\>

-John

–  
John S.  
Computing Staff - Webmaster  
Kavli Institute for Theoretical Physics  
University of California, Santa Barbara  
removed\_email\_address@domain.invalid  
(805) 893-6307
