# Params on controller and view

**URL:** <https://www.ruby-forum.com/t/params-on-controller-and-view/99092>\
**Category:** Rails\
**Created:** [January 30, 2006, 10:59pm UTC](https://www.ruby-forum.com/t/params-on-controller-and-view/99092 "2006-01-30T22:59:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Human\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/edb3f5/32.png) [@Human\_D](https://www.ruby-forum.com/u/Human_D)\
**Post date:** [January 30, 2006, 10:59pm UTC](https://www.ruby-forum.com/t/params-on-controller-and-view/99092/1 "2006-01-30T22:59:58Z")

</div>

Hi,  
I have a link that says:  
\<%= link\_to\_remote(“Data”, :update =\> ‘pie\_graph\_div’, :url =\> {  
:action =\> :show\_pie\_graph, :mode =\> ‘nums’ }) %\>

which calls _show\_pie\_graph_:  
Controller:  
def show\_pie\_graph  
render :layout =\> false  
@mode = params[:mode]  
end  
View:  
 ![](https://www.ruby-forum.com/surveys/make_pie_graph/<%=@mode%>)

But @mode on view always is nil.  
I can see the :mode from the view by calling params[:mode] but not  
from the controller.

What’s the problem? Did I misunderstand something?

Thanks in advance,

- H

---

<div class="post-metadata">

**Author:** ![Human\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/edb3f5/32.png) [@Human\_D](https://www.ruby-forum.com/u/Human_D)\
**Post date:** [January 30, 2006, 11:18pm UTC](https://www.ruby-forum.com/t/params-on-controller-and-view/99092/2 "2006-01-30T23:18:05Z")

</div>

Human D. wrote:

> from the controller.  
> Set @mode before calling render.

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![Human\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/edb3f5/32.png) [@Human\_D](https://www.ruby-forum.com/u/Human_D)\
**Post date:** [January 30, 2006, 11:27pm UTC](https://www.ruby-forum.com/t/params-on-controller-and-view/99092/3 "2006-01-30T23:27:09Z")

</div>

Thanks

---

<div class="post-metadata">

**Author:** ![Human\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/edb3f5/32.png) [@Human\_D](https://www.ruby-forum.com/u/Human_D)\
**Post date:** [January 31, 2006, 2:19am UTC](https://www.ruby-forum.com/t/params-on-controller-and-view/99092/4 "2006-01-31T02:19:23Z")

</div>

You need to swap the lines in the controller.

```
def show_pie_graph
	@mode = params[:mode]
	render :layout => false
end

```

The ‘render’ method uses the current state of the controller at the time  
it  
is called to setup the view. At that time, @mode is not yet set, so  
that is  
what the view sees.
