So all you need to do is define to_model on your decorator? Not so fast! Rails
has some other surprises up its sleeve.

How about something like this:

<%=form_forProfile.new(User.new)do|f|%><%end%>

You might expect this form to POST to /profiles but instead it will submit
to /users. Isn’t the path based on the class name? Apparently not. Instead the
URL is built based on attributes of your object’s model_name. Since
model_name is delegated to the underlying user, the form submits to /users.

If you’re decorating an ActiveRecord or ActiveModel object in Rails, you
probably want to define the following to ensure the decorator works the way you
expect instead of silently delegating to the underlying object:

If you enjoyed this post, you might also like:

Want to level up your testing game?
Learn about testing Rails applications and TDD
in our new book
Testing Rails.
The book covers each type of test in depth,
intermediate testing concepts,
and anti-patterns that trip up even intermediate developers.