Adding to objects returned by AR

Ahoy,

I have a location object that looks something like this when using
<%= debug @location %>

— !ruby/object:Location
attributes:
title: The Studio
id: “3”
zip_id: “40915”
address: 9013 Main Street

I want to add a another method, “godzilla”

— !ruby/object:Location
attributes:
title: The Studio
id: “3”
zip_id: “40915”
address: 9013 Main Street
godzilla: “raaaaaaaa”

How do i do this?

In your “location” model,

attr_accessor :godzilla

Is that what you’re asking?

Jason

Jason,

Then :godzilla is nil by default.
attr_accessor :godzilla
allows me to do in the controller

@godzilla = “asdf”

then

location.godzilla will return “asdf”

but how do i set that as a default in the model?

In your “location” model,

attr_accessor :godzilla

Is that what you’re asking?

Jason

Chris H wrote:

Hello,

I store sessions in my database and I’d like to store a session_id
with a user when they log in. How do I determine what a user’s session
id is?

session.session_id

The reason I want to do this is because I’d like to display users
currently logged in.

session.session_id won’t help here as it applies to the current user
only.

If I can link a session to a user in my database, then I can check the
updated_at column
in the sessions table and determine who is active.

Is this the correct way to go about doing this?

There was a similar discussion about this previously. Basically you
already
have access to the user session in the AR Store. You just need a way to
differentiate a user session from anonymous ones, if you have both
session
types.

It might be possible to add a user_id column to the AR Store table and
populate the column when a user logs in. Alternatively, record users in
a
separate user_table. You will have more flexibility in storing and
managing
user info with this approach.

HTH,

Long
www.edgesoft.ca/blog/read/2 - rails articles

Hello,

I store sessions in my database and I’d like to store a session_id
with a user when they log in. How do I determine what a user’s session
id is?

The reason I want to do this is because I’d like to display users
currently logged in.

If I can link a session to a user in my database, then I can check the
updated_at column
in the sessions table and determine who is active.

Is this the correct way to go about doing this?

thanks in advance,
Chris.

take a look at this for some info:

http://habtm.com/articles/2005/12/15/whos-online

Hi Chris,

Chris H wrote:

How do I determine what a user’s session id is?

If I can link a session to a user in my database, then
I can check the updated_at column in the sessions
table and determine who is active.

session[:id] will give you the id of the current session, but I don’t
think
that’s what you’ll end up wanting.

hth,
Bill