narozk
October 11, 2007, 8:16pm
1
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 %>
narozk
October 11, 2007, 8:20pm
2
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 %>
narozk
October 11, 2007, 8:21pm
3
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
narozk
October 11, 2007, 8:22pm
4
but how can I set the variable in link_to_remote ?
narozk
October 11, 2007, 9:12pm
5
Are you expecting PHP-like behavior here?
What exactly are you trying to do?
Jason
narozk
October 11, 2007, 9:51pm
6
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…
narozk
October 12, 2007, 12:50am
7
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
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
Also, just in case you don’t know about the MVC pattern (what Rails is
built
upon), there’s information here:
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
Let us know if you need any specific help!
Jason