Taking Post as an example model, let's say Post has 2 attributes, both of which have validations. When going to edit a post, say I change the 2 attributes, and one fails validation, causing the page to be reloaded. It appears to me that when the page is reloaded, the previously saved versions of the post's attributes are displayed in the form, and not the attributes I just entered, though the ones I just entered are in the params.
This would be handled in typical create actions because the post instance variable declaration would look like this:
@post = Post.new(params[:post])
However, in update actions, the post instance variable looks like this:
@post = Post.find(params[:id])
Therefor, the changes entered into the form, which are passed into the params are not re-rendered on the form. Am I describing this correctly, and if so, is there a way I can get the changes to be rendered with the form when validation fails? Or perhaps, only the changes which don't fail validation?
as corey says you need to update the attributes on update so:
@post = Post.find(params[:id])
if @post.update_attributes(params[:post])
redirect_to post_path(@post)
else
render :new
end
you are currently not updating the instance of post, so you see what is in the database.