Closed HuckyDucky closed 9 years ago
Sounds like a Rails autoloader problem. I'm pretty sure your upload gem somewhere keeps a reference to the contract class where the validation is used in. This breaks autoloading. Can you point me to the carrierwave_direct source, I can have a quick look.
Use paperdragon if you're sick of all this ActiveRecord mess.
Ahh. That could be it. The source is at https://github.com/dwilkie/carrierwave_direct.
I'm checking out paperdragon now. It's early enough in this project that I could get away with it.
It looks like it's for images, and this particular use case is for CSV and XML files, but there doesn't appear to be anything preventing that.
One question I have as I'm almost through the TRB book as it's written thus far. I'm in the process of deprogramming myself from slamming everything into models. It's liberating, but it's taking me a while to learn where stuff goes and why it goes there. I'm trying to boil the book contents down to a series of bullet points that will help me grok Trailblazer in fullness.
Something I can't seem to get past is, under what circumstances would I use a regular method rather than create an Operation? Should I think of Operations as being a level of abstraction above a method?
It seems like most Operations are CRUD. But if I have an app where the user needs to do things like:
Do these things sound like Operations? It seems to me like they do.
Whereas, for the "Upload a file" operation, maybe the file has to be a certain size, or has to have certain headers in it. "Check header" doesn't sound like an Operation, it sounds like it's just a method. Because a user of the site doesn't care about "Checking the header", they're just trying to "Upload a file". It's the "Upload a file" Operation that needs to call a method "check_header". Am I thinking about this right?
And if I am, here's my next question. Where do I put the methods? My instinct is to make them private methods of the Operation classes.
If they don't need to be reused, that's fine. If they do need to be reused, what is the preferred way of allowing that:
require
d and Include
d by whatever needs itNick,
I'm looking for information on Authorization, which looks like it's coming up in the next chapter of the book. Do you know any gems on Github that are doing authorization within TB? I imagine it's within the process
method of the validation, but I'm probably missing other stuff.
I also wanted to offer to edit the Trailblazer book.
Hey @HuckyDucky go ahead an email me when you have suggestions etc. for the book! Can't wait!
We will be using pundit and other gems to actually implement the roles and permissions, Trailblazer is simply gonna streamline that so you can easily have nested permissions in operations/contracts/representers.
The more feedback I get about that from people using authorization gems, the better!
I don't have your email.
It's on my GH profile! :stuck_out_tongue:
BTW - please don't use an issue as a discussion forum. For instance, I completely missed to answer the new questions on this one.
To answer you last questions about when to use operations: Whenever a function is a public function of your application, whether you invoke that from a controller via the UI, via the console or in a test.
Everything else does not have to be an operation, because it's not a public concept. I usually have PORO classes inline in the operation to solve "smaller" issues, as the operation is an orchestrating director and not a monolith.
Does that make it easier to understand? Feel free to email me about that, too. :stuck_out_tongue_winking_eye:
Chapter 8 (coming in a few days) discusses a file upload, albeit with Paperdragon.
Perfect timing.
Hey guys. I like to use the
carrierwave_direct
gem to do direct uploads to S3. In this new project, I'm creating operations for anUpload
model I have.carrierwave_direct
extends AR validations to offer an:is_uploaded
feature.Like all validations, I want to put that in the contract in Create operation in
app/concepts/upload/crud.rb
.To make a field on a model "uploadable" with this gem, you have to add:
to your model. I'm trying to put it in my Upload namespace in the
crud.rb
file, which is where it really belongs.I'm getting an error on the validation though, and it's a screwed-up error:
What the bloody hell that means I don't know. Here's the code:
The error is occurring just on running a console or server. The stacktrace points to that line: