Próbuję zaimplementować przesyłanie plików za pomocą AngularJS/Rails przy użyciu klejnotu Paperclip. Rozwiązuję problem z wprowadzaniem pliku za pomocą dyrektywy. Teraz chcę wysłać obraz z innymi danymi postu, ale dane obrazu nie są wysyłane.Przesyłanie pliku Paperclip AngularJS/Rails
HTML:
<form name="PostForm" ng-submit="submit()" novalidate>
<input type="text" ng-model="post.title">
<input type="file" file-upload />
<textarea ng-model="post.content"></textarea>
</form>
Mój kontroler:
$scope.create = function() {
function success(response) {
console.log("Success", response)
$location.path("posts");
}
function failure(response) {
console.log("Failure", response);
}
if ($routeParams.id)
Post.update($scope.post, success, failure);
else
Post.create($scope.post, success, failure);
}
$scope.$on("fileSelected", function (event, args) {
$scope.$apply(function() {
$scope.post.image = args.file;
});
Mój model:
class Post < ActiveRecord::Base
attr_accessible :content, :title, :image_file_name, :image_content_type, :image_file_size, :image_updated_at
belongs_to :user
has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
end
Ale kiedy wysłać go na stronie serwera, żądanie jest tak:
{
"content":"Hey",
"created_at":"2013-08-31T17:54:32Z",
"id":17,
"image_content_type":null,
"image_file_name":null,
"image_file_size":null,
"image_updated_at":null,
"title":"Image",
"updated_at":"2013-08-31T17:54:32Z",
"user_id":4
}
W związku z tym żadne dane dotyczące zachowania obrazu nie są wysyłane na serwer, żadne wskazówki, jak to zrobić?
Hey Joe, to potęga pomocna https: //gist.github .com/vajapravin/48059fd9d64bb42f012f513cebd391ea – vajapravin