小编Joe*_*Bow的帖子

AngularJS/Rails Paperclip文件上传

我尝试使用Paperclip gem实现使用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>
Run Code Online (Sandbox Code Playgroud)

我的控制器:

$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;
    });
Run Code Online (Sandbox Code Playgroud)

我的模特:

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 …
Run Code Online (Sandbox Code Playgroud)

javascript file-upload ruby-on-rails paperclip angularjs

6
推荐指数
1
解决办法
2060
查看次数