Closed edudouglas closed 7 years ago
This seems to be more of a rails-logic question instead of parse-stack specifically. From the sample above, you will most likely always go to redicrect_to @film
since as long as valid?
is true it will save the @film
(regardless of success or failure` and go to the proper view. I would recommend using a more direct approach of (even testing on rails console or byebug).
attrs = # get attrs from params for :film
@film.name = attr[:name] # and inspect what you are getting
if @film.valid? && @flim.save
redirect_to @film
else
render 'edit'
end
If you can provide a more detail exampled of an issue you are having with latest version of parse-stack, that would be best.
The problem is that after the model validates the data and verify that it has an error it goes to the "edit" method, however, this "edit" goes with the path as if it were to create a new record and consequently ends up going to the "create".
attrs = #get attrs from params for: film
@film.name = attr[:name] # and inspect what you are getting
if @film.valid? && @flim.save
redirect_to @film
else
# should go to /film/objectId/edit
# and display errors on the screen with @film.errors
# but it is going to /film/objectId
# and submitting again goes to "create" instead of "update"
render 'edit'
end
It is not a problem of routes because I created a scaffold for testing with an sqlite database and everything works normally. Sorry for my english.
Thanks for the last answer, I found a problem when I was trying to validate the data before saving the edition, in my model, I defined something as:
property: name, required: true
when opening a record to edit and leave the empty "name" field goes to redirected to the "update" method, if I send the form again goes to the "create" method, the form path becomes "new_film" instead of "edit_film".