[Rails] updating database on show
Jens-Christian Fischer
jcf at invisible.ch
Tue Nov 16 12:21:48 GMT 2004
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
More information about the Rails
mailing list