I checked out a Rails sample project, for jquery fileuploads The project itself works, but it's running on 3.2.13.
Now I want to use this code in my own Project, which is based on Rails 4.2.3.
First it didn't work, cause I ran into the error undefined method 'attr_accessible' for #<Class:0x007f7428f82f98>
I found out, that there was a change in Rails 4.1, regarding the "mass alignment". Now I am trying to convert this to Rails 4...
Here is my Upload model:
class Upload < ActiveRecord::Base
attr_accessible :upload
has_attached_file :upload
include Rails.application.routes.url_helpers
def to_jq_upload
{
"name" => read_attribute(:upload_file_name),
"size" => read_attribute(:upload_file_size),
"url" => upload.url(:original),
"delete_url" => upload_path(self),
"delete_type" => "DELETE"
}
end
end
I have deleted everything inside the model-class, and got rid of the error. But now my Rails Application does not accept the uploads. (Nothing happens, when I try to upload a file) I have added the following code to my controller, but it still doesn't accept my uploaded files.
uploads_controller:
def upload_params
params.require(:upload).permit(:name, :size, :url, :delete_url, :delete_type)
end
Can you guys help me, to get this to work on Rails 4?
Best regards
Aucun commentaire:
Enregistrer un commentaire