Forum: Ruby on Rails attachment_fu

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0fdce938a28a604fd5613a68b0d78fcb?d=identicon&s=25 Jose vicente Ribera pellicer (joripel)
on 2009-03-05 16:44
First at all sorry if my english is not the best

I have a problem with this plugin. It has been installed because we need
to upload images in our web. We need 3 kinds of images with different
sizes.

this is our code:

Image model:

class Image < ActiveRecord::Base
.
.
.

has_attachment  :content_type => ['image/jpeg', 'image/pjpeg',
'image/gif', 'image/jpg', 'image/png'],
                              :storage => :file_system,
                              :path_prefix => 'public/images',
                              :size => 1.kilobyte..300.kilobytes,
                              :resize_to => '700>',
                              :thumbnails => { :titular1 => '220>',
:titular2 => '150>', :foro => '440>'  },
                              :processor => :MiniMagick

  validates_as_attachment


-------------------------------------
the name of the controller is titulares. The code is like that :

class TitularesController < ApplicationController
.
.
.
def edit
    @titulo = "Editar titular"
    @titular = Contenido.find(params[:id])
  end
.
.
.
def create
    @titular=Contenido.new(params[:contenido])
    @titular.subtipo_id=Subtipo::TITULARES

    # Actualizo el usuario, incrementando sus puntos y su nº de posts de
blog
    autor = Usuario.find(@titular.usuario_id)
    estadisticas_up(autor.id, Subtipo::TITULARES)
    autor.update_attribute("puntos", autor.puntos + @titular.puntos_msg)
    autor.update_attribute("puntos_anual", autor.puntos_anual +
@titular.puntos_msg)
-----------------------------------------------------
/*this is the part of code for the images*/
-----------------------------------------------------
    respond_to do |format|
      if @titular.save
        #guardo las imagenes
        unless (image = params[:image]).nil?
          img = Image.new(image.merge({:usuario_id =>
session[:usuario_id], :contenido_id => @titular.id, :orden =>1}))
          img.save
        end
        format.html { redirect_to(portada_titulares_path) }
        format.xml  { render :xml => @titular, :status => :created,
:location => @titular }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @titular.errors, :status =>
:unprocessable_entity }
      end
    end
  end
.
.
.
----------------------------------------------------------


OK, when I edit a titular there's no problem. I can add or edit a photo
perfectly and in my BBDD there are the 3 images with the respective
size. the problem exits whe i want to create a titular, I can add an
image but my BBDD only stores the original image with the original size.
There is not the copies with another sizes.

I don´t know because the anothers sizes  there aren´t written in the
BBDD...any help please???
0fdce938a28a604fd5613a68b0d78fcb?d=identicon&s=25 Jose vicente Ribera pellicer (joripel)
on 2009-03-05 17:07
I replace img.save with img.save! and the result is the same.
0fdce938a28a604fd5613a68b0d78fcb?d=identicon&s=25 Jose vicente Ribera pellicer (joripel)
on 2009-03-05 17:23
solved, it doesn´t work fine in localhost but in the server there's no
problem
This topic is locked and can not be replied to.