Params in partials

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’ %>


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

  • <%= link_to_remote “HOTEL”, :url =>
    { :action => ‘index’, :thistheme => 1 },
    => ‘resultsTable’,
    => “‘thiscity=’+escape($F(‘city_lookup’))” %>

  • <% else %>
  • <%= link_to_remote “HOTEL”, :url => { :action =>
    ‘index’, :thistheme => 1 },
    => ‘resultsTable’,
    => “‘thiscity=’+escape($F(‘city_lookup’))” %>

  • <% end %>

    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 %>

    Why are you using params? You should be either setting a member variable
    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


    but how can I set the variable in link_to_remote ?

    Are you expecting PHP-like behavior here?

    What exactly are you trying to do?


    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…

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

    If you are up to buying a book, I highly recommend Agile Development
    Rails v2: Pragmatic Bookshelf: By Developers, For Developers

    Unfortunately, free tutorials on the net aren’t easy to find that help
    but here’s the Rails wiki page:

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

    In short, link_to_remote sends an Ajax call to a controller (#index, in
    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
    practice anyways.

    Also, here’s the Rails API docs:

    Let us know if you need any specific help!