Closed huynhlv closed 4 years ago
Hi @huynhlv , I'm not sure I understand what's the issue. Looking at your first screenshot, line 15 looks weird, what is pitch
in that line: pitch owner.image.attach(param)
?
Hi @huynhlv , I'm not sure I understand what's the issue. Looking at your first screenshot, line 15 looks weird, what is
pitch
in that line:pitch owner.image.attach(param)
?
Hi @santib, thank you for responding! VsCode not show '_' in terminal :smile: Before line this code i have set param = params[:image] My code in controller:
@huynhlv ok great. So just to double check, you are saying that it's working fine to you if you attach images from the rails console but it's not from the rails server (controller), right?
Would you mind providing:
?
That way we can try to reproduce the issue.
@santib Yes, that right!
gem 'active_storage_base64'
@huynhlv You can check the Gemfile.lock
to see which version of active_storage_base64
you are using
@santib Yes, It is version 0.1.4
@huynhlv I think I was able to reproduce your case. If you don't "permit" the params you are using in the attach
method seems that it doesn't work. Would you mind confirming it?
https://apidock.com/rails/ActionController/Parameters/permit
@santib I try set param1 = params.require(:image).permit(:data)
When I check byebug in terminal, data param1 is: <ActionController::Parameters {"data"=>"data:image/png;base64,iVB..."} permitted: true>
Then, I checked again as below
@huynhlv Look this is my debugging:
try with .to_h
so that you actually send a hash to the attach
method instead of sending an ActionController::Parameters
object.
Also make sure that you are seeing logs, maybe for some reason they are not getting displayed when you debug (for some config you might have in your project), just in case double check in log/development.log
@santib Thank you so much, it worked well
I see your README
class UsersController < ApplicationController
def create
user = User.create(user_params)
user.avatar.attach(params[:avatar])
end
private
def user_params
params.require(:user).permit(:username, :email)
end
end
@huynhlv You are right, that doesn't seem to work. Would you be interested in opening a PR so that we allow ActionController::Parameters
to be sent to the attach
methods? The conversion to a hash could be done within the attach
method.
EDIT:
We should add tests that work with ActionController::Parameters
in the different scenarios described by the README and make sure we either make all of them work or we update the README.
Hi, I'm getting this error ActiveStorage::Attachment Load nil In my controller:
def create pitch_owner = PitchOwner.create(user_id: 1) pitch_owner.image.attach(params[:image]) end
My Parameters: {"image"=>{"data"=>"data:image/png;base64,iVBO..."}, "pitch_owner"=>{"pitch_name"=>"abc"}} In rails server, it can't load active_storage_attachments but in rails console with this code I can create success active_storage_attachments Thanks so much!