I''m trying to have an application that models a number of rooms and a
number of people that can move between the rooms.
The models are like this:
Room:
class Room < ActiveRecord::Base
has_many :people
end
Person:
class Person < ActiveRecord::Base
belongs_to :room
[...]
end
I display a room with links to all linked rooms (/room/show/2,
room/show/4,...)
Now I want the current person (as in the session object) to "know"
which
room he''s in. I tried the following in my room controller:
def show
room_id = @params["id"]
@room = Room.find( room_id )
if !@session["current_room_id"]
@session["current_room_id"] = room_id
end
person = @session["person"]
person.room = Room.find( @session["current_room_id"] )
person.save
end
but that doesn''t seem to work...
I thought about adding a "move" action that moves to a new room, but
I''m
not sure how I can extract the new room id
Any ideas?
thanks
jc
On Tue, 16 Nov 2004 13:21:48 +0100, Jens-Christian Fischer <jcf-m2zzWtmgR3gXXHkOk0aIfQ@public.gmane.org> wrote:> Now I want the current person (as in the session object) to "know" which > room he''s in. I tried the following in my room controller: > > def show > room_id = @params["id"] > @room = Room.find( room_id ) > if !@session["current_room_id"] > @session["current_room_id"] = room_id > end > person = @session["person"] > person.room = Room.find( @session["current_room_id"] ) > person.save > end > > but that doesn''t seem to work...What about: def show @room = Room::find(@params[''id'']) @session[''person''].room = @room @session[''person''].save end -- Regards, John Wilger ----------- Alice came to a fork in the road. "Which road do I take?" she asked. "Where do you want to go?" responded the Cheshire cat. "I don''t know," Alice answered. "Then," said the cat, "it doesn''t matter." - Lewis Carrol, Alice in Wonderland
> > but that doesn''t seem to work... > What about: > def show > @room = Room::find(@params[''id'']) > @session[''person''].room = @room > @session[''person''].save > endthanks - I''m slowly wrapping my head around the things one can do with Rails. I''ll give that a try later and see if this works for me. jc