Evaluating variables in Rails views -- help!

Hi Matthew,

Matthew Rogers wrote:

the if(params[:id] == p.id) never seems to evaluate to true.

What am I missing? Is there a better way to do this? Thanks!

You do not have access to the params hash in the browser. The params hash sends user-entered data to the server and is constructed by the browser when a request is sent. The inverse mechanism in Rails is instance variables. They are used by Rails to construct the page sent by the server to respond to the browser's request.

You haven't included enough code to give specific advice, so here's the generality. If the value you're looking for is something that was passed to the server in the last request, after saving it in either the database or a session variable if you're going to need it later, assign it to an instance variable so you'll have access to it in the view in this cycle. If the value you're looking for is something the user entered on the page in this cycle, then you'll need to access it via it's DOM address, possibly using javascript.

hth, Bill

excuse me while i reiterate everything everyone has already said :stuck_out_tongue_winking_eye: