How would i go about using a mapped resource in my model? eg. # routes file map.resources :questions # model def after_create notification = UserNotification.new(:user => current_user) notification.body = ''You posted a new <a href="'' + question_url(question.id) + ''">question</a>'' notification.save end comes up saying undefined method for question_url --~--~---------~--~----~------------~-------~--~----~ 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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 1/26/08, Chubbs <acetinick-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > How would i go about using a mapped resource in my model? > > eg. > # routes file > map.resources :questions > > # model > def after_create > notification = UserNotification.new(:user => current_user) > notification.body = ''You posted a new <a href="'' + > question_url(question.id) + ''">question</a>'' > notification.save > end > > comes up saying undefined method for question_urlWell, since url helpers are UI constructs, they really shouldn''t be used directly by models. They are available in controllers and views. I''d humbly suggest that the best way to solve this is to have the UserNotification have a reference to the question, and then use question_url in UserNotificationsController and/or it''s views. This would properly keep the M-VC business logic-ui separation. -- Rick DeNatale My blog on Ruby talklikeaduck.denhaven2.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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
mmm ok thanks the help On Jan 28, 12:34 am, "Rick DeNatale" <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 1/26/08, Chubbs <acetin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > How would i go about using a mapped resource in my model? > > > eg. > > # routes file > > map.resources :questions > > > # model > > def after_create > > notification = UserNotification.new(:user => current_user) > > notification.body = ''You posted a new <a href="'' + > > question_url(question.id) + ''">question</a>'' > > notification.save > > end > > > comes up saying undefined method for question_url > > Well, since url helpers are UI constructs, they really shouldn''t be > used directly by models. They are available in controllers and views. > > I''d humbly suggest that the best way to solve this is to have the > UserNotification have a reference to the question, and then use > question_url in UserNotificationsController and/or it''s views. > > This would properly keep the M-VC business logic-ui separation. > > -- > Rick DeNatale > > My blog on Rubyhttp://talklikeaduck.denhaven2.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 groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---