I''m using the restful_authentication plugin/generator to user access control in an app I''m working on. I added on to the user model for things like male/female. I have two methods on the user model male? and female?. I have two fields in a model that has a one-to-many relationship with the User model that are only needed if the current_user.female? is true. However I''m not sure how I would call the method from a model that is not the User model. Can anyone offer some advice? Thanks, Tim K. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
try current_user.male? and current_user.female? check out lib/authenticated_system.rb in your project. this will give you some insight on how to work with logged in users. good luck. mike On Dec 20, 2007, at 5:54 PM, blaine wrote:> > I''m using the restful_authentication plugin/generator to user access > control in an app I''m working on. I added on to the user model for > things like male/female. I have two methods on the user model male? > and female?. I have two fields in a model that has a one-to-many > relationship with the User model that are only needed if the > current_user.female? is true. However I''m not sure how I would call > the method from a model that is not the User model. Can anyone offer > some advice? > > Thanks, > > Tim K. > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
sorry, I misread your question... On Dec 20, 2007, at 5:54 PM, blaine wrote:> > I''m using the restful_authentication plugin/generator to user access > control in an app I''m working on. I added on to the user model for > things like male/female. I have two methods on the user model male? > and female?. I have two fields in a model that has a one-to-many > relationship with the User model that are only needed if the > current_user.female? is true. However I''m not sure how I would call > the method from a model that is not the User model. Can anyone offer > some advice? > > Thanks, > > Tim K. > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
has_many :ovaries, :if => :female? ^ Something like this? -- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
No problem Michael, yeah - I''ve tried that... The only way I can think of doing it is assigning an instance variable that I can check from the model. But that just doesn''t seem right. Anyone else have any thoughts? On Dec 20, 9:20 pm, Michael Breen <hard...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> sorry, I misread your question... > > On Dec 20, 2007, at 5:54 PM, blaine wrote: > > > > > I''m using the restful_authentication plugin/generator to user access > > control in an app I''m working on. I added on to the user model for > > things like male/female. I have two methods on the user model male? > > and female?. I have two fields in a model that has a one-to-many > > relationship with the User model that are only needed if the > > current_user.female? is true. However I''m not sure how I would call > > the method from a model that is not the User model. Can anyone offer > > some advice? > > > Thanks, > > > Tim K.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sorta Ryan... more like validates_presence_of :ovaries, :if => :female? However ovaries is in one model and :female? is a method on the user model. On Dec 20, 9:21 pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> has_many :ovaries, :if => :female? > > ^ Something like this? > > -- > Ryan Bigghttp://www.frozenplague.net--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Do you have a relationship (belongs_to, has_many) set up on these other models with your User model? Could you pass a value into a method on these other classes and then use a dynamic finder on User? OtherClass def my_method name u = User.find_by_username name end It''s tough to figure it out without knowing how these other models are set up. On Dec 20, 2007, at 9:22 PM, blaine wrote:> > No problem Michael, yeah - I''ve tried that... The only way I can > think of doing it is assigning an instance variable that I can check > from the model. But that just doesn''t seem right. Anyone else have > any thoughts? > > On Dec 20, 9:20 pm, Michael Breen <hard...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> sorry, I misread your question... >> >> On Dec 20, 2007, at 5:54 PM, blaine wrote: >> >> >> >>> I''m using the restful_authentication plugin/generator to user access >>> control in an app I''m working on. I added on to the user model for >>> things like male/female. I have two methods on the user model male? >>> and female?. I have two fields in a model that has a one-to-many >>> relationship with the User model that are only needed if the >>> current_user.female? is true. However I''m not sure how I would call >>> the method from a model that is not the User model. Can anyone >>> offer >>> some advice? >> >>> Thanks, >> >>> Tim K. > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Dec 21, 2007 12:57 PM, blaine <jangchub-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Sorta Ryan... more like > > validates_presence_of :ovaries, :if => :female? > > However ovaries is in one model and :female? is a method on the user > model. > > On Dec 20, 9:21pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > has_many :ovaries, :if => :female? > > > > ^ Something like this? > > > > -- > > Ryan Bigghttp://www.frozenplague.net > > >And precisely WHAT is the problem with doing that? If ovaries is a model then it will work. -- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Michael, there is definitely a relationship. Here let me give you some better details. I''m calculating lean body mass which is different for both men and women. I have the User model that restful_authentication generates with a few added fields one of which is User.sex, and a has_many :measurements relationship. I then have two methods in the generated User model as such: def male? self.sex == "male" end def female? self.sex == "female" end I have a Measurements model which has a relationship with the user using belongs_to :user. I have two fields that are I want to validate the presence of only in the case were current_user.female? is true. Hope that clears it up a little more. Tim On Dec 20, 9:29 pm, Michael Breen <hard...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Do you have a relationship (belongs_to, has_many) set up on these > other models with your User model? > > Could you pass a value into a method on these other classes and then > use a dynamic finder on User? > > OtherClass > > def my_method name > u = User.find_by_username name > end > > It''s tough to figure it out without knowing how these other models are > set up. > > On Dec 20, 2007, at 9:22 PM, blaine wrote: > > > > > No problem Michael, yeah - I''ve tried that... The only way I can > > think of doing it is assigning an instance variable that I can check > > from the model. But that just doesn''t seem right. Anyone else have > > any thoughts? > > > On Dec 20, 9:20 pm, Michael Breen <hard...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> sorry, I misread your question... > > >> On Dec 20, 2007, at 5:54 PM, blaine wrote: > > >>> I''m using the restful_authentication plugin/generator to user access > >>> control in an app I''m working on. I added on to the user model for > >>> things like male/female. I have two methods on the user model male? > >>> and female?. I have two fields in a model that has a one-to-many > >>> relationship with the User model that are only needed if the > >>> current_user.female? is true. However I''m not sure how I would call > >>> the method from a model that is not the User model. Can anyone > >>> offer > >>> some advice? > > >>> Thanks, > > >>> Tim K.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
validates_presence_of :field1, :field2, :if => :female? -- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
validates_presence_of :wrist_inches, :if => :female? Results in: undefined method `female?'' for #<Measurement:0x1123378> On Dec 20, 9:51 pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> validates_presence_of :field1, :field2, :if => :female? > > -- > Ryan Bigghttp://www.frozenplague.net--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
And a measurement belongs to a user? class Measurement < ActiveRecord::Base validates_presence_of :wrist_inches, :if => "female" def female? user.female? end end Here I was thinking you were putting the VPO in the User model. Silly me. On Dec 21, 2007 1:24 PM, blaine <jangchub-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > validates_presence_of :wrist_inches, :if => :female? > > Results in: > > undefined method `female?'' for #<Measurement:0x1123378> > > On Dec 20, 9:51pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > validates_presence_of :field1, :field2, :if => :female? > > > > -- > > Ryan Bigghttp://www.frozenplague.net > > >-- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Remember female? is a method of a different model. I think the issue here is really how do I call the current_user object that restful_auth sets as a local variable from other models. Because logic tells me I could create a method on the the Measurements model that does: def current_user_is_female User.find_by_id(current_user.id).female? end and then doing: validates_presence_of :wrist_inches, :if => :current_user_is_female But doing that of course leaves me with a "undefined local variable or method `current_user'' for #<Measurement:0x1736bac>" Tim On Dec 20, 9:51 pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> validates_presence_of :field1, :field2, :if => :female? > > -- > Ryan Bigghttp://www.frozenplague.net--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Awesome Ryan - that was exactly it! I needed to make a another definition for female? -- Perfect! :D You rock man! Tim On Dec 20, 9:58 pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> And a measurement belongs to a user? > > class Measurement < ActiveRecord::Base > validates_presence_of :wrist_inches, :if => "female" > def female? > user.female? > end > end > > Here I was thinking you were putting the VPO in the User model. Silly me. > > On Dec 21, 2007 1:24 PM, blaine <jangc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > validates_presence_of :wrist_inches, :if => :female? > > > Results in: > > > undefined method `female?'' for #<Measurement:0x1123378> > > > On Dec 20, 9:51pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > validates_presence_of :field1, :field2, :if => :female? > > > > -- > > > Ryan Bigghttp://www.frozenplague.net > > -- > Ryan Bigghttp://www.frozenplague.net--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---