Reputation: 353
I am working on a Rails 5 app and have a model called @offer. In the Offers controller I have an action where I want to redirect to a specific offer I got from the database (Offer Id = 14 in the examples below.)
Working in the development environment, if I use redirect_to offer_path(@offer.id) in the controller, the browser correctly displays the offer in the https://dev.example.com/offers/14 URL. Notice the dev part in the URL. So far so good.
However, if I use redirect_to @offer in the controller, the browser tries to open the https://example.com/offers/14 URL (that's the production URL) and the page shows an error (We're sorry, but something went wrong. If you are the application owner check the logs for more information.)
I would like to use redirect_to @offer, but first, I think I need to understand why one redirect method behaves differently than the other. Thanks for any insight.
Upvotes: 0
Views: 214
Reputation: 398
This question is old but still I am answering as it might help other rails users in the future.
In Offers controller redirect_to @offer or redirect_to offers_path(@offer) would resolve to the same path /offers/:id be it production or development.
I think, in the production database offer with id 14 does not exist and also in the controller, if op is using find method without rescuing exception then, the show action might be erroring while trying to fetch the Offer with id 14 from the production database but the find method my have returned exception which if not rescued the rails might show a default error response.
We don't have controller code posted by the op but to me, this seems to be the most logical answer.
Upvotes: 1