Unable to reset file error in rails

I am developing an application with Rails 3.0.3.

I got the message "Can not dump file" in the following code.

if @post.update_attributes params[:post] redirect_to post_path(@post) #<= ERROR HERE 

After googling, I added 2 lines to fix this.

  if @post.update_attributes params[:post] params[:post][:photos_attributes] = nil params[:post][:attachments_attributes] = nil redirect_to post_path(@post) 

Now the error has disappeared. But I do not understand why the error occurred and how it is fixed. I use active_record for session storage and this caused an error because the file could not be saved to the database. But why is redirect_to trying to store the file in the session?

Thanks.

Sam

+4
source share
3 answers

I am not sure about photo_attributes and attachment_attributes . I assume that they contain some kind of information about files, and saving them does not work correctly.

Maybe you can post your Post model for us?

0
source

I assume attachment_attributes contains uploaded files.

Loaded files are stored in parameters, because ActionDispatch :: Http :: UploadedFile objects and objects of this type are not serializable, therefore, an error.

0
source

Addendum: ActiveRecord::SessionStore::Session.serializer = :json in config / application.rb solved the problem for me.

0
source

Source: https://habr.com/ru/post/1335357/


All Articles