2017-12-13 17 views
0

Ich arbeite derzeit an Rails-Anwendung. alles ist gut. Ich schrieb SQL-Abfrage und bekam die Image_file_name wie Photo.all.select("photos.id, photos.image_file_name"), aber ich möchte auch vollständige URL des Bildes analysieren. Gibt es irgendeinen Weg, dies für mich zu tun?Schienen - Get Paperclip URL mit SQL-Abfrage

Ich brauche eine Ausgabe wie

[ 
    #<Photo id: 1, image_file_name: photo1, image_url: '/system/photos/images/000/000/86/thumb/photo1.png?1511864359'>, 
    #<Photo id: 2, image_file_name: photo2, image_url: '/system/photos/images/000/000/382/thumb/photo2.png?1511864359'>, 
    #<Photo id: 3, image_file_name: photo3, image_url: '/system/photos/images/000/000/102/thumb/photo3.png?1511864359'>, ...] 

Antwort

0

ich nicht sicher, aber irgendwie kann es Ihnen helfen.

Photo.all.collect{|p| [p.id, p.image_file_name, p.image.path]} 

das Sie so als Array zur Folge geben und Sie können es als ein Array durchlaufen: -

[[4,"photo1","/system/photos/images/000/000/86/thumb/photo1.png?1511864359"], 
[5,"photo2","/system/photos/images/000/000/382/thumb/photo2.png?1511864359'"], 
[6,"photo3","/system/photos/images/000/000/102/thumb/photo3.png?1511864359"]] 
0

die Sie interessieren, wird es Ihnen das Ergebnis geben, wie Sie benötigen:

Photo.select { |p| [p.id, p.image_file_name, p.image.path] }