lundi 11 septembre 2017

The passed data is ModelObject::ActiveRecord_Relation, not String Rails 5

Im trying to obtain the id from a table using a where clause, but the value return as an ActiveRecord_Relation.

def generate_qrcode
    idBuscado = get_id_beneficio(3) #the 3 it's just for testing values
    qrcode = make_qrcode(idBuscado)
    send_data qrcode.to_s, type: 'image/png', disposition: 'inline'
  end


private def get_id_beneficio(idBuscado)
    itemlist = Beneficio.select('Id_beneficio', :conditions => ['id_beneficio = ?', "%#{idBuscado}%"]).limit(1)
  end

private def make_qrcode(cadena = 0)
    qrcode = RQRCode::QRCode.new(cadena)
    image = qrcode.as_png(
        resize_gte_to: false,
        resize_exactly_to: false,
        fill: 'white',
        color: 'red',
        size: 300,
        border_modules: 3,
        module_px_size: 4,
        file: nil # path to write
        )
    image.resize(150, 150)
  end

and the error that show... Error

i need to now how to get the value named Id_beneficio and return it as a Integer. Any advice? :(

Aucun commentaire:

Enregistrer un commentaire