Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file is prefixed and can't be shown #2766

Closed
UmPlat opened this issue Nov 30, 2024 · 1 comment
Closed

file is prefixed and can't be shown #2766

UmPlat opened this issue Nov 30, 2024 · 1 comment

Comments

@UmPlat
Copy link

UmPlat commented Nov 30, 2024

Mac Sequoia, Rails 8, ruby 3.3.5, gem carrierwave version 3.07, sqlite

When serialize :avatars, JSON in Post model.
rails c:
post = Post.last
raises `class:Post': wrong number of arguments (given 2, expected 1) (ArgumentError)

ChatGpt advices to comment this line for Rails 8.
Err gone and
rails c:
post = Post.last
files = [
File.open(Rails.root.join('storage', 'Carolyn1.jpg'))
]
post.avatars = files
post.save!
post.avatars.map(&:url) #["/uploads/post/avatars/9/Carolyn1.jpg"]

But when get /posts

I see prefix and suffix around the file and img can't be shown

@UmPlat
Copy link
Author

UmPlat commented Dec 2, 2024

I found solution:
just add
attribute :avatars, :json, default: []
to a model

@mshibuya mshibuya closed this as completed Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants