Ruby on Rails Monday, October 20, 2014

What's the current best practice for getting the userID from the sesson,
and having it be part of every newly created/modified record?

I have an app with a Club model and a People model, and a "membership"
join table.

class Club < ActiveRecord::Base
has_many(:memberships)
has_many(:members, class_name: 'People', through: :memberships)
end

I want all the tables, including the membership join table, to have a
"creator" field that gets populated every time the record is created
updated. I'd especially like to do stuff in my controller like the
following:
c = Club.find(name: => 'The Rubyists')
c.members << People.find(name: ['Joe','Ann'])

and have it populate the membership table correctly.

Google has found me various articles/posts related to various versions
of rails, some of which say something like "if you're doing this,
you're Doing It Wrong", and many of which suggest putting information
in a thread-local variable.

I worry that some of these suggestions I've find make assumptions about
how Rails works under the hood that may not hold true for every
deployment method.

Any ideas?
In addition to general advice, I'd be interested in any gems that try to
provide a solution to this.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/20141020133430.7107688da69493e2663876a4%40brisammon.fastmail.fm.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment