Upload with angularjs and rails 4
Upload with angularjs and rails 4
我想在我的帖子中上传一张插图图像,我已经安装了carrierwave和angularjs文件上传,但它不起作用
%form.edit-user{:role => "form", :multipart => "true"}
[..another field of my post..]
%input{:type => "file", :name => "image", "nv-file-select"=>"", "uploader"=>"uploader"}
我已经把这个代码写进了我的表单,我的载波类:
class ImageUploader < CarrierWave::Uploader::Base
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
我的型号:
class Recette < ActiveRecord::Base
mount_uploader :image, ImageUploader
end
和我的控制器:
def create
@recette = Recette.new(params.require(:recette).permit(:name,:instructions))
@recette.image = params[:image]
@recette.save
render 'show', status: 201
end
我已经将模块加载到我的应用程序angular中,并将其添加到我的控制器中:
$scope.uploader = new FileUploader({url: '/recettes/new'}, {alias: 'image'});
我使用jbuilder gem和我的_recette.json.jbuilder:
json.(recette, :id, :name, :instructions, :image)
感谢您的帮助
解决了这个问题:
$scope.uploader = new FileUploader({url: '/recettes/new'}, {alias: 'image', formData: 'Your Data'});
您需要在"formData"对象中指定所有数据都将随上传一起发送。
请参阅文档
相关文章:
- 如何从rails中的代码中删除新行( )
- Rails File_field最大堆栈大小
- Ajax and Json with Rails
- Rails 3.2 and Paloma gem
- Upload with angularjs and rails 4
- geolocation with javascript and ruby on rails
- Rails CORS and jQuery autocomplete
- Rails 4, recaptcha and turbolinks
- jquery val(); function and ruby on rails
- AJAX and Rails: Parsererror
- Rails 4 - nested_form and chosen-select
- Backbone and Rails Associations: 避免 JSON HashWithIndifferent
- Rails 3.1 and Javascript templates
- 都不是:method =>:post and:remote =>true正在我的Rails 3.1应用程序上工作
- Ruby on Rails Gemfile Development and Javascript
- Javascript and Rails Interaction
- Shared Rails and JavaScript views
- Javascript, Rails views, content_for and DRYness
- ruby on rails - haml and javascript
- Rails 4 and jQuery UI