I trying to create a blog with a obligatory image, but after create, when i try to edit this blog, his image appears on thmbnail but not in field and i have to select the image again.
For upload image i use the carrierwave gem.
My model
class Blog < ActiveRecord::Base
validates :name, :description, :picture, presence: true
mount_uploader :picture, BlogPictureUploader
def picture_url
picture.url
end
My view
= simple_form_for [blog] do |f|
.row
.col-md-6
.panel.panel-default
.panel-heading Foto
.panel-body
.thumbnail class="#{blog.picture? ? "" : "hide"}"
= image_tag blog.picture
p= f.input :picture, label: 'Selecione a foto:', hint: 'A foto deve ter 270x270.'
My controller
class BlogsController < ApplicationController
expose(:blog, attributes: :blog_params)
def update
authorize blog
blog.save
respond_with blog, location: [:blog]
end
The behavior on edit: edit view after click button
Aucun commentaire:
Enregistrer un commentaire