Can't change instance variable

I have an instance variable @grp: (app\controllers\zwemmers_controller.rb) class ZwemmersController < ApplicationController ...   def initialize     @grp='or1r2r3r4gggrp'   end   attr_accessor :grp ... end

When i click an image, i reload the main index page and try to change the value of the variable: (app\views\layouts\zwemmers.html.erb)

... <%= link_to image_tag("oranje.png", :mouseover => image_path("oranje2.png"), :grp => 'o'), zwemmers_path %> ...

The value doesn't change. any ideas?

I have an instance variable @grp: (app\controllers\zwemmers_controller.rb) class ZwemmersController < ApplicationController ... def initialize @grp='or1r2r3r4gggrp' end

In general I'd be wary of overriding initialize without calling super (i think you're ok here though)

attr_accessor :grp ... end

When i click an image, i reload the main index page and try to change the value of the variable: (app\views\layouts\zwemmers.html.erb)

... <%= link_to image_tag("oranje.png", :mouseover => image_path("oranje2.png"), :grp => 'o'), zwemmers_path %> ...

The value doesn't change. any ideas?

You haven't shown anywhere where you're trying to set it - if you want it to be set based on a parameter, you're going to have to set @grp to params[:something]

Fred

Frederick Cheung wrote in post #980057:

You haven't shown anywhere where you're trying to set it - if you want it to be set based on a parameter, you're going to have to set @grp to params[:something]

Hm, i forgot the on_click in my code: <%= link_to image_tag("oranje.png", :mouseover => image_path("oranje2.png"), :onclick => (:grp => 'o')), zwemmers_path %>

So when i click the image i want to redirect to zwemmers_path and i want to change the value of @grp to 'o'. I don't know how to implement params tho.

If you don't know about passing data back to the controller via params then you need to run through some basic guides and tutorials. See the Rails Guides (google it) and railstutorial.org is good.

Make sure that any tutorial you use matches the rails version you are using (2 or 3). I would advise using Rails 3 unless you are to maintain legacy apps.

Colin

K thanks for the responses, i will do some reading on params. Didn't know changing the value of an instance variable is this complicated.

It isn't complicated, most things seem complicated till you know how and have had a bit of practice :slight_smile:

Colin