-
Notifications
You must be signed in to change notification settings - Fork 4
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
Undefined method _attacher
#2
Comments
@Arvinje Can you post me your exact setup? Perferably in a self-contained script which I can run with require "shrine"
require "shrine/storage/file_system"
require "tmpdir"
Shrine.storages = {
cache: Shrine::Storage::FileSystem.new(Dir.tmpdir),
store: Shrine::Storage::FileSystem.new(Dir.tmpdir),
}
Shrine.plugin :activerecord
Shrine.plugin :reform
class CampaignCoverUploader < Shrine
end
require "active_record"
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.connection.create_table(:records) { |t| t.text :compaign_cover_data }
class Record < ActiveRecord::Base
include CampaignCoverUploader[:campaign_cover]
end
require "reform"
require "reform/rails"
class Form < Reform::Form
include CampaignCoverUploader[:campaign_cover]
end
record = Record.new
form = Form.new(record)
form.validate(campaign_cover: File.open(__FILE__))
form.save
puts record.campaign_cover For some reason this script raises an error for me on the
|
@janko-m I ran the script you purposed. (The exact same one) |
Hey, I'm also experiencing the same issue when using Dry validations. The issue is that the attacher instance variable is not available within the If I replace
with
It has access to the attacher and can add any errors. Hope this helps you identify and resolve the issue. |
P.S seems to be working fine when using Active Model validations. |
@coatezy Thanks for the info, I will definitely look into this soon. Being able to use |
@janko-m Good to hear. If I get 5 minutes I will ask over on the Trailblazer Gitter room to see if anyone can suggest where is best to check/assign any errors in a way that works for both ActiveModel and Dry validations. |
@janko-m Not sure if you ever had a chance to look in to this? I am now using shrine-reform with Dry-V. My previous work around worked okay until I had multiple uploaders within a single form. Because I was calling super within a class_eval only the final validator worked. I am now using prepend and all validators work as expected. 😄 Replaced:
With:
|
I haven't had a chance too look at this, thank you for the update! I you have time, I would definitely appreciate a pull request for this 😉 |
Sorry @janko-m - Only just returned to the project that required TRB/Shrine file uploads. The approach above worked fine until I wanted to check for the presence of the upload using DRY-V. With a presence validation on image Dry responds with a not present validation error.
There must some kind of ordering issue as if I move
above Happy to continue playing if you have any suggestions on where I can look next. 😉 |
@coatezy Ah, I'm guessing Reform internals changed a bit since I wrote shrine-reform. I think The main problem was defining properties corresponding to the possible Shrine attributes, so that it passes Reform's mass assignment, but without defining accessors for those attributes (as it should use Shrine's accessors), and without attempting to sync them, because any assignment through those attributes write data to the Those were the main challenges, it would be great if you could find time to look into it a bit deeper. I cannot find time lately, latest updates to tus-ruby-server took a significant portion of my energy 😛 |
Let's wait until Reform 2.3.0 is released, and go from there (it's currently in RC phase). |
Had a chat with Nick and when using Trailblazer he believes that the uploader should not be part of the form/contract. I have now written a step to handle uploading within the operation.
I do often use Reform on it's own though so would be great to see this plugin work Reform and Dry-V in the future. 😄 |
I'm using shrine 2.5.0, reform 2.2.3 and shrine-reform 0.1.4 and I get this exception whenever I try to validate:
undefined local variable or method `campaign_cover_attacher' for #<#<Class:0x007fda5eb59a60>:0x007fda5eca7a70>
I simply added
CampaignCoverUploader[:campaign_cover]
to both the form and the model and now I'm getting the error when i callvalidate
on the form object. Seems like it's expecting this method to be available on the model, 'cause as soon as I implement an attr_accessor forcampaign_cover_attacher
, the error changes.Did I set it up correctly? am I missing something?
The text was updated successfully, but these errors were encountered: