carrierwave - How to get id of created image in rails -
i have recipe model , recipephoto model. want show thumbnail of scaled image on creating new recipe. upload photo through jquery-file-upload. problem don't know how id of uploaded photo.
example:
user creating new recipe. loads photo , crops on server , see thumbnail preview before submitting recipe.
recipes_controller.rb
def new @recipe = recipe.new @recipe_photo = recipephoto.new end
recipes/new.html.slim
= simple_form_for @recipe, :html => {:class => 'add-recipe-form'} |recipe| .form-inputs = recipe.input :title .form-actions = recipe.submit "create recipe" = form_for @recipe_photo |f| .form-inputs = f.label :image, "upload paintings:" = f.file_field :image, multiple: false
recipe_photo.js.coffee (here can filename, not record_id)
$ -> $('.new_recipe_photo').fileupload datatype: "script" done: (e, data) -> console.log data.files[0], data.files[0].name
recipe_photo.rb
class recipephoto < activerecord::base attr_accessible :recipe_id, :image belongs_to :recipe mount_uploader :image, recipeimageuploader end
Comments
Post a Comment