我尝试使用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)