hi, i''m working on an idea of mine using ruby on rails but totally stumped with the has_many :notes, belongs_to :users in ruby could someone explain this to me? basically every user will be able to create many notes (notes being a record with a body text field), but those individual notes will only relate to the user who created them. so joe won''t be able to see sally''s note records how do i do this? can anyone point me to an easy example, done the authentication and everything else, just can''t get my head around this one. appreciate it, John. -- View this message in context: http://www.nabble.com/joining-notes-to-users--tf4101141.html#a11662669 Sent from the RubyOnRails Users mailing list archive at Nabble.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?hl=en -~----------~----~----~----~------~----~------~--~---
Hi! By what i can understand is "Creator alone see his/her own notes". For this you need to store creator_id or user_id in the notes table ans wherever you are displaying the notes just check if the note if from the user who has logged in. So, say session[:id] is having the id of the user who has logged in and in the rhtml somewhere you are having, @notes as collection of notes then while displaying you can write <%for note in @notes <%if note.user_id == session[:id]%> Show notes data here <%end%> <%end%> Hope this helps, :) Thanks and regards, Swanand On 7/18/07, indiehead <indiehead-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > hi, i''m working on an idea of mine using ruby on rails but totally stumped > with the has_many :notes, belongs_to :users in ruby > > could someone explain this to me? > > basically every user will be able to create many notes (notes being a > record > with a body text field), but those individual notes will only relate to > the > user who created them. > > so joe won''t be able to see sally''s note records > > how do i do this? > > can anyone point me to an easy example, done the authentication and > everything else, just can''t get my head around this one. > > appreciate it, > > > John. > -- > View this message in context: > http://www.nabble.com/joining-notes-to-users--tf4101141.html#a11662669 > Sent from the RubyOnRails Users mailing list archive at Nabble.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?hl=en -~----------~----~----~----~------~----~------~--~---
if you just want to display the notes specific to the currently logged in user, you''d just use something like this (assuming current_user returns the currently logged in user): in your model: user.rb class User < ActiveRecord::Base # each user will have many notes, each note will be associated with # a user through a user_id column in the notes table has_many :notes end note.rb class Note < ActiveRecord::Base # a note belongs to a single belongs_to :user end in your controller: def notes #retrieve all the notes for the currently logged in user @notes = current_user.notes end and in your view: <% for note in @notes %> <%= note.title %> <%= note.body %> .... <% end %> Mike On 7/18/07, swanand deodhar <swanand.blms-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi! > By what i can understand is "Creator alone see his/her own notes". For > this you need to store creator_id or user_id in the notes table ans wherever > you are displaying the notes just check if the note if from the user who has > logged in. > So, say session[:id] is having the id of the user who has logged in and > in the rhtml somewhere you are having, @notes as collection of notes then > while displaying you can write > <%for note in @notes > <%if note.user_id == session[:id]%> > Show notes data here > <%end%> > <%end%> > Hope this helps, :) > > Thanks and regards, > Swanand > > > On 7/18/07, indiehead <indiehead-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > hi, i''m working on an idea of mine using ruby on rails but totally stumped > > with the has_many :notes, belongs_to :users in ruby > > > > could someone explain this to me? > > > > basically every user will be able to create many notes (notes being a > record > > with a body text field), but those individual notes will only relate to > the > > user who created them. > > > > so joe won''t be able to see sally''s note records > > > > how do i do this? > > > > can anyone point me to an easy example, done the authentication and > > everything else, just can''t get my head around this one. > > > > appreciate it, > > > > > > John. > > -- > > View this message in context: > http://www.nabble.com/joining-notes-to-users--tf4101141.html#a11662669 > > Sent from the RubyOnRails Users mailing list archive at Nabble.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?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Mike and Swanand, helped me out of a jam at the 11th hour. Appreciate it, John. -- 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?hl=en -~----------~----~----~----~------~----~------~--~---