简体   繁体   中英

cannot print database records in ruby on rails

Am trying to print Database records. When I run the code below from retrieve_all.html

I can print my sent name but can't print the attachment records. all am seeing in the command prompt is

select 'attachments',*From 'attachments'

my name: is Nancy More
my all: #<Attachment::ActiveRecord_Relation:0x090d4820>

it seems that @attachment variable is empty. Any idea on what is going on I deally I should also be printing id, filename etc.

print('fid: ', @attachment.id)
print('fname: ', @attachment.filename)

here is the code.

def retrieve_all
    name = 'nancy More'
    print('my name is: ', name)
    @attachment = Attachment.all
    print('my all: ', @attachment)

    # providing that gem 'jbuilder', '~> 2.0'  in the gemfile and display records in json
    #render json: @attachment = Attachment.all


end

The above code posted is working fine. The issue was caused by images that was stored in the database as binary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM