Comments (2)
Hey @andregoldstein ,
Ideally, you'd want to tell the model to skip ActiveRecord callbacks in the after_build
callback. Ex:
after_build do |product|
product.skip_callbacks!
end
It doesn't seem that Active Record offers a way to skip callbacks that would work well with csv-importer
, so you'd want to implement your own logic:
Ex:
class Product < ApplicationRecord
after_save_commit :set_prices, unless: :skip_callbacks?
after_save_commit :broadcast_updates, unless: :skip_callbacks?
def skip_callbacks!
@skip_callbacks = true
end
def skip_callbacks?
@skip_callbacks == true
end
I hope that helps!
from csv-importer.
Thanks for your reply, I'll try and implement that!
from csv-importer.
Related Issues (20)
- How to find_by another model's attribute? HOT 1
- Allow manual mapping HOT 2
- Adding an error to a row from a to: block? HOT 3
- Cannot access instance variable in after_build HOT 1
- skip! does not indicate which row was skipped in the report HOT 1
- Many to many association HOT 1
- Encodings HOT 1
- Encoding - German Umlaute ignored. HOT 1
- Upload file HOT 5
- Add i18n to messages HOT 2
- Exception when model.save fails HOT 2
- Memory bloat when processing large files HOT 2
- Make transactions optional HOT 4
- A normalization feature? HOT 4
- German umlauts issue HOT 3
- Ruby 2.7.1 - ArgumentError: unknown encoding name - UTF-8:UTF-8 HOT 2
- Question: Pass a parameter to an import? HOT 6
- Question: Is there a way to programmatically get the column mapping to see which columns of the CSV file are being mapped to which columns/attributes of the model?
- Rails 6.1 errors hash deprecation warning HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from csv-importer.