views:

28

answers:

1

To clean up my code I would like access to the RESTful helpers in my Rails model. Something like:

users_path

etc.

Thanks.

+1  A: 

Why do you want to access routes in your model? This is a violation of the Model/View/Controller (MVC) pattern that is at the heart of Rails. Models shouldn't have any knowledge of routes which are a controller and view concern. Models should stand alone from the user interface.

If you told us what you are trying to achieve then we may be able to suggest a better approach.

John Topley
I'm sending a Twitter post after a new item is created on the web site. I want to use "after_create" to create the Tweet - hence I need a link back to the item.Instead of a call in the controller which passes in the restful route, which is how I'm doing it now, I want to implement skinny controller - fat model.Yes it only means removing a single line from a controller, but if it can be done ...
Jez Caudle
I think that in this case it's appropriate to do the work in the controller.
John Topley