Vinay
2008-Oct-11 09:15 UTC
Virtual attribute setter method in model, how to write a scoped query?
I have a form that has a virtual attribute ''contact_name''. In the setter method for this, I need to scope the query through current_user.contacts.find (etc). But current_user is a helper method (RESTful authentication) and it is apparently not available in the model (where the setter method is located). I tried.. [code=]@current_user = User.find(params[:user_id]) @contact = @current_user.contacts.find (etc)[/code] .. but the params hash too is not available. How can I scope the query through the current_user in the model file? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Vinay
2008-Oct-13 10:57 UTC
Re: Virtual attribute setter method in model, how to write a scoped query?
anyone got any ideas? i really need a solution for this to get a feature working. On Oct 11, 2:15 pm, Vinay <yourstruly.vi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a form that has a virtual attribute ''contact_name''. In the > setter method for this, I need to scope the query through > current_user.contacts.find (etc). But current_user is a helper method > (RESTful authentication) and it is apparently not available in the > model (where the setter method is located). I tried.. > [code=]@current_user = User.find(params[:user_id]) > @contact = @current_user.contacts.find (etc)[/code] > .. but the params hash too is not available. How can I scope the query > through the current_user in the model file?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---