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

Importing records, a way to ignore initial state #29

Closed
akatz opened this issue Mar 1, 2011 · 4 comments
Closed

Importing records, a way to ignore initial state #29

akatz opened this issue Mar 1, 2011 · 4 comments
Assignees

Comments

@akatz
Copy link

akatz commented Mar 1, 2011

I wrote a bulk uploader importing existing data in csv form. Unfortunately the state is reset regardless of the state on import. Is there any way to ignore set_initial_state so I can import existing data?

@alto
Copy link
Member

alto commented Sep 16, 2011

Is this what you want to achieve?

class ImportedData
  aasm_initial_state :open
  aasm_state :open
  aasm_state :closed
end

data = ImportedData.create(:data => '...', :aasm_state => 'closed')

data.closed? # => true

@ghost ghost assigned alto Sep 16, 2011
@srayhan
Copy link

srayhan commented Nov 18, 2011

Alto, I also have the same need. Is this supported?

@akatz
Copy link
Author

akatz commented Jan 13, 2012

alto,
I haven't gotten the hang of GH notifications yet, my apologies. Yes that is what I need. The ability on create to be able to overwrite the state.

@alto
Copy link
Member

alto commented Feb 27, 2013

Sorry for not having come back to this earlier on.

This behaviour is supported for persisted objects (ActiveRecord, etc.), so in my example it should be

class ImportedData < ActiveRecord::Base
...

For all other classes you could define an initializer like this:

class ImportedData
  def initialize(attributes)
    self.current_state = attributes[:aasm_state]
  end
  ...
end

@alto alto closed this as completed Feb 27, 2013
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

3 participants