# Params in partials

**URL:** <https://www.ruby-forum.com/t/params-in-partials/116976>\
**Category:** Rails\
**Created:** [October 11, 2007, 8:16pm UTC](https://www.ruby-forum.com/t/params-in-partials/116976 "2007-10-11T20:16:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![narozk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/d78d45/32.png) [@narozk](https://www.ruby-forum.com/u/narozk)\
**Post date:** [October 11, 2007, 8:16pm UTC](https://www.ruby-forum.com/t/params-in-partials/116976/1 "2007-10-11T20:16:13Z")

</div>

I have a navigation bar which buttons should activate themselves on  
click but  
“params[:thistheme]” is always nil in my partial. Why?

## my view

## \<%= render :partial =\> ‘shared/themeMnuBtn\_1’ %\>

## \_themeMnuBtn\_1

\<% if params[:thistheme] == 1 %\>

## 
- \<%= link\_to\_remote “ **HOTEL** ”, :url =\>  
{ :action =\> ‘index’, :thistheme =\> 1 },  
:update  
=\> ‘resultsTable’,  
:with  
=\> “‘thiscity=’+escape($F(‘city\_lookup’))” %\>
  
\<% else %\>  
- \<%= link\_to\_remote “ **HOTEL** ”, :url =\> { :action =\>  
‘index’, :thistheme =\> 1 },  
:update  
=\> ‘resultsTable’,  
:with  
=\> “‘thiscity=’+escape($F(‘city\_lookup’))” %\>
  
\<% end %\>

---

<div class="post-metadata">

**Author:** ![narozk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/d78d45/32.png) [@narozk](https://www.ruby-forum.com/u/narozk)\
**Post date:** [October 11, 2007, 8:20pm UTC](https://www.ruby-forum.com/t/params-in-partials/116976/2 "2007-10-11T20:20:17Z")

</div>

looks better:

\<% if params[:thistheme] == 1 %\>

- \<%= link\_to\_remote " **HOTEL**",:url =\> { :action =\> 'index', :thistheme =\> 1 }, :update =\> 'resultsTable', :with =\> "'thiscity='+escape($F('city\_lookup'))" %\> 
 \<% else %\> - \<%= link\_to\_remote " **HOTEL**", :url =\> { :action =\> 'index', :thistheme =\> 1 }, :update =\> 'resultsTable', :with =\> "'thiscity='+escape($F('city\_lookup'))" %\> 
\<% end %\>

---

<div class="post-metadata">

**Author:** ![narozk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/d78d45/32.png) [@narozk](https://www.ruby-forum.com/u/narozk)\
**Post date:** [October 11, 2007, 8:21pm UTC](https://www.ruby-forum.com/t/params-in-partials/116976/3 "2007-10-11T20:21:23Z")

</div>

Why are you using params? You should be either setting a member variable  
or  
using the flash if this is a one-time good thing.

From the looks of it, you want a member variable. aka \<% if @this\_theme  
== 1  
%\>

Jason

---

<div class="post-metadata">

**Author:** ![narozk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/d78d45/32.png) [@narozk](https://www.ruby-forum.com/u/narozk)\
**Post date:** [October 11, 2007, 8:22pm UTC](https://www.ruby-forum.com/t/params-in-partials/116976/4 "2007-10-11T20:22:50Z")

</div>

but how can I set the variable in link\_to\_remote ?

---

<div class="post-metadata">

**Author:** ![narozk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/d78d45/32.png) [@narozk](https://www.ruby-forum.com/u/narozk)\
**Post date:** [October 11, 2007, 9:12pm UTC](https://www.ruby-forum.com/t/params-in-partials/116976/5 "2007-10-11T21:12:28Z")

</div>

Are you expecting PHP-like behavior here?

What exactly are you trying to do?

Jason

---

<div class="post-metadata">

**Author:** ![narozk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/d78d45/32.png) [@narozk](https://www.ruby-forum.com/u/narozk)\
**Post date:** [October 11, 2007, 9:51pm UTC](https://www.ruby-forum.com/t/params-in-partials/116976/6 "2007-10-11T21:51:20Z")

</div>

Well, link\_to\_remote sets “:thistheme =\> 1” (I can access to it in my  
controller). So I know button 1 (=thistheme 1) was clicked. In this case  
my button should get the style “themeMnu1Active”. That’s all. I thought  
the best way would be to use already available informations:  
params[:thistheme]. but it’s nil in my partial. And yes, unfortunately I  
am influenced by php…

---

<div class="post-metadata">

**Author:** ![narozk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/d78d45/32.png) [@narozk](https://www.ruby-forum.com/u/narozk)\
**Post date:** [October 12, 2007, 12:50am UTC](https://www.ruby-forum.com/t/params-in-partials/116976/7 "2007-10-12T00:50:42Z")

</div>

Well, as it stands, you need to stop what you’re doing and read up on  
how  
Rails works.

If you are up to buying a book, I highly recommend Agile Development  
with  
Rails v2: [Pragmatic Bookshelf: By Developers, For Developers](http://www.pragprog.com/title/rails/)

Unfortunately, free tutorials on the net aren’t easy to find that help  
out,  
but here’s the Rails wiki page:  
[http://wiki.rubyonrails.org/rails/pages/GettingStartedWithRails](http://wiki.rubyonrails.org/rails/pages/GettingStartedWithRails)

Also, just in case you don’t know about the MVC pattern (what Rails is  
built  
upon), there’s information here:

> **[Model–view–controller](https://en.wikipedia.org/wiki/Model-view-controller)**
>
> Model–view–controller (MVC) is a software design pattern commonly used for developing user interfaces that divides the related program logic into three interconnected elements. This is done to separate internal representations of information from the ways information is presented to and accepted from the user.
> Traditionally used for desktop graphical user interfaces (GUIs), this pattern became popular for designing web applications. Popular programming languages have MVC frameworks that facilita...

In short, link\_to\_remote sends an Ajax call to a controller (#index, in  
this  
case). params[] is available in that controller for you to use. I don’t  
think that’s what you want. Stick to non-Ajax calls (#link\_to), it’s  
good  
practice anyways.

Also, here’s the Rails API docs: [http://api.rubyonrails.org](http://api.rubyonrails.org)

Let us know if you need any specific help!

Jason
