0

I'm using Rails 4 and ActiveModel:Model for an app that will do a calculation and display the result to the user. I don't want to save the calculations to a database as they will only be used once and discarded. However, I don't know how to display the results of the calculation as using redirect_to @calculation doesn't work.

I've done some Googling and I can't find any examples of people using tableless models in a view. Is there any way to do this?

Chris Lawrence
  • 281
  • 1
  • 4
  • 7

1 Answers1

0

You can't redirect to the resource, because as soon as the request ends, and you didn't save the resource, it no longer exists. There is no ID with which to find it in the next request.

You have 2 simple options- save the calculations, or render the page you want directly, such as:

render 'calculations/show'

Perhaps it would make more sense to use a plain old ruby object instead of a model, as its assumed eventually a model should be persisted.

AJcodez
  • 31,780
  • 20
  • 84
  • 118