Rails 4 Carrierwave, post updating isn't working correctly after implementing multiple uploads -


i implemented multiple uploads carrierwave , i'm unable update post correctly. here controller:

class postscontroller < applicationcontroller     before_action :find_posts, only: [:show, :edit, :update, :destroy, :upvote, :downvote]     before_action :authenticate_user!, except: [:index, :show, :home]      def home     end      def index         if params[:category].blank?             @posts = post.all.order("created_at desc")         else             @category_id = category.find_by(name: params[:category]).id               @posts = post.where(category_id: @category_id).order("created_at desc")           end     end      def show         @inquiries = inquiry.where(post_id: @post).order("created_at desc")         @random_post = post.where.not(id: @post).order("random()").first         @post_attachments = @post.post_attachments.all      end      def new         @post = current_user.posts.build         @post_attachment = @post.post_attachments.build     end      def create         @post = current_user.posts.build(post_params)         respond_to |format|             if @post.save                  params[:post_attachments]['image'].each |a|                     @post_attachment = @post.post_attachments.create!(:image => a)                 end                 format.html { redirect_to @post, notice: 'post created.' }             else                  format.html { render action: 'new' }             end         end     end      def update       if @post.update(post_params)         flash[:notice] = "post updated!"         redirect_to @post       else         flash[:notice] = "something went wrong...give shot!"         render 'edit'       end     end      def edit     end        def destroy     @post.destroy     respond_to |format|       format.html { redirect_to posts_url, notice: 'post destroyed.' }       format.json { head :no_content }     end   end      def upvote         @post.upvote_by current_user         redirect_to @post     end      def downvote         @post.downvote_by current_user         redirect_to @post     end      private      def find_posts          @post = post.find(params[:id])     end      def post_params         params.require(:post).permit(:title, :price, :description, :location, :category_name, :contact_number, :image)     end end 

basically, post creating fine, when attempt update images, new images doesn't replace old ones. i'm not sure how go changing update have accept new images. note: other fields work when update, not images.

what change in controller make work? if need see form or else, let me know, i'm quite it's in controller.

since said creating post working fine. updating post not. after looking @ code, seems expected, def update missing code have in def create params[:post_attachments]['image'] part.

just in case not know yet, def create called when click submit button in new-post form, while def update called when click submit button in edit-post form.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -