Hello I have a pretty basic question here. I have articles and users. I have added a user_id field to the articles table. I would like to insert the user session id (they have to login) into the articles table once a user creates an article. Id appreciate any help or links for doing this task. Thanks Eoghan
On Sun, 2005-10-16 at 13:07 +0100, eoghan wrote:> Hello > I have a pretty basic question here. I have articles and users. I > have added a user_id field to the articles table. I would like to > insert the user session id (they have to login) into the articles > table once a user creates an article. Id appreciate any help or links > for doing this task.Are you sure that you want to save the session id? How are you saving the sessions, database, pstore, other? Short of using the database, you aren''t likely to have the data for very long. Also if a user logs out, would that eliminate your access to the data linked by the session id. And would a user deleting cookies or logging into the app from a different machine cause a similar disruption of what you are intending? Depending on what your intentions are, you should probably go from the article to the user and then from the user to the sessions. -- Steven Critchfield critch-wQLwMjUOumVBDgjK7y7TUQ@public.gmane.org KI4KTY
Steven wrote:> On Sun, 2005-10-16 at 13:07 +0100, eoghan wrote: >> Hello >> I have a pretty basic question here. I have articles and users. I >> have added a user_id field to the articles table. I would like to >> insert the user session id (they have to login) into the articles >> table once a user creates an article. Id appreciate any help or links >> for doing this task. > > Are you sure that you want to save the session id? How are you saving > the sessions, database, pstore, other? Short of using the database, you > aren''t likely to have the data for very long. Also if a user logs out, > would that eliminate your access to the data linked by the session id. > And would a user deleting cookies or logging into the app from a > different machine cause a similar disruption of what you are intending? > > Depending on what your intentions are, you should probably go from the > article to the user and then from the user to the sessions.Hi Stephen, Well what im wanting to do is insert the userid for each article they create. This is currently stored in the session cookie once they login. They have to be logged in to create articles. I have the user_id field created in the articles table. But as far as rails goes, im not 100% sure where to proceed from here... Just looking for some direction on how this would be achieved in a rails way... Thanks Eoghan
Approximately: @user.articles << @article -- -- Tom Mornini On Oct 17, 2005, at 1:44 AM, eoghan wrote:> Steven wrote: > >> On Sun, 2005-10-16 at 13:07 +0100, eoghan wrote: >> >>> Hello >>> I have a pretty basic question here. I have articles and users. >>> I have added a user_id field to the articles table. I would like >>> to insert the user session id (they have to login) into the >>> articles table once a user creates an article. Id appreciate any >>> help or links for doing this task. >>> >> Are you sure that you want to save the session id? How are you saving >> the sessions, database, pstore, other? Short of using the >> database, you >> aren''t likely to have the data for very long. Also if a user logs >> out, >> would that eliminate your access to the data linked by the session >> id. >> And would a user deleting cookies or logging into the app from a >> different machine cause a similar disruption of what you are >> intending? >> Depending on what your intentions are, you should probably go from >> the >> article to the user and then from the user to the sessions. >> > > Hi Stephen, > Well what im wanting to do is insert the userid for each article > they create. This is currently stored in the session cookie once > they login. They have to be logged in to create articles. I have > the user_id field created in the articles table. But as far as > rails goes, im not 100% sure where to proceed from here... > Just looking for some direction on how this would be achieved in a > rails way... > Thanks > Eoghan > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Mon, 2005-10-17 at 02:00 -0700, Tom Mornini wrote:> Approximately: > > @user.articles << @articleThe above is correct. I''ll elaborate a bit since I think you(Eogan) may not understand the above. Article belongs to User. User has many Articles. This gives you @user.articles == list of articles by this user @user.articles << @article adds @article to the list of articles by user @user.articles << Article.new(attr) same as above. @article.user == user who authored @article @article.user.articles == list of articles by the author of this article> > Hi Stephen, > > Well what im wanting to do is insert the userid for each article > > they create. This is currently stored in the session cookie once > > they login. They have to be logged in to create articles. I have > > the user_id field created in the articles table. But as far as > > rails goes, im not 100% sure where to proceed from here... > > Just looking for some direction on how this would be achieved in a > > rails way... > > Thanks > > Eoghan-- Steven Critchfield critch-wQLwMjUOumVBDgjK7y7TUQ@public.gmane.org KI4KTY
On 17 Oct 2005, at 17:51, Steven wrote:> On Mon, 2005-10-17 at 02:00 -0700, Tom Mornini wrote: > >> Approximately: >> >> @user.articles << @article >> > > The above is correct. I''ll elaborate a bit since I think you(Eogan) > may > not understand the above. > > Article belongs to User. > User has many Articles. > > This gives you > @user.articles == list of articles by this user > @user.articles << @article adds @article to the list of articles by > user > > @user.articles << Article.new(attr) same as above. > > @article.user == user who authored @article > @article.user.articles == list of articles by the author of this > articleThanks for the explanation. It seems a lot clearer to me now. Eoghan