Post
:belongs_to :user
User
:has_many :posts
In my signup workflow they draft a Post first, then on the next page enter their User information to signup.
# intermediate step, validate that Post is valid before moving on to User creation
# posts_controller:
@post = Post.new(params[:post])
if @post.valid?
# go on to create User
else
render 'new'
end
BUT! @post error messages aren’t created since I’m not saving the @post model I’m just checking for .valid?. How do I create the error messages without saving?
If I understand your question correctly you want to get the errors without saving the model?
That is exactly what is happening.
@post.valid?will return true or false depending on whether there are any errors. If there are errors. they will be added to
@post.errorshash.In the situation where you want to save just call
@post.saveIt will return true if successfully saved or false if errors are present while populating
@post.errorsin the process