Using route resource in the model

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 question
notification.save
end

comes up saying undefined method for question_url

On 1/26/08, Chubbs [email protected] wrote:

notification.body = 'You posted a new <a href="' +

question_url(question.id) + ‘">question’
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 Ruby
http://talklikeaduck.denhaven2.com/

mmm ok thanks the help

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs