Jay Mittal
2006-Aug-23 23:27 UTC
[Rails] Re: Displaying only that data which is associated to logged
Thanks for your reply Koala. I''ll describe what all tables and
relationships I have.
---------------------------------------------------------------------------
Tables: 1) User 2) Courses
Relationships - Model : User - has_many courses
Model : Course - belongs_to user
DB Table ''courses'' has user_id.
----------------------------------------------------------------------------
I am using LoginGenerator gem so when a user logs in - a
session[''user'']
is created which is an array of user.id, user.login and user.password.
Right.
Now, when I have to show only those courses associated to the who logged
in is by putting a SQL statement which will be "SELECT * FROM courses
WHERE user_id = session[''user''].id" ... am i right?
Also, when this logged in user creates a new course then user_id gets
value from session[''user''].id ... is session variable
available in model
too, or just controllers or views? How shall I do this?
When I try to achieve all this I get the following stupid error :
Called id for nil, which would mistakenly be 4 -- if you really wanted
the id of nil, use object_id
PLEASE HELP:
Jay.
koloa wrote:> i plan on doing something similiar. it seems like there is a simple
> relationship where you would have a table titled users that is linked to
> another with a has_many relationship to a table titled courses. where
> after sombody logins, that grants them access to the controller that
> selects all courses where id == user id. i think also you may need to
> store a session in a file to let your code know that only the user that
> is logged in only can view and modify where his name matches up with
> whatever is in the row.
>
> do a search for login generator "ruby on rails". other than that,
it may
> just be simple sql statements.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---