Skip to content

Instantly share code, notes, and snippets.

@jcutrell
Last active August 29, 2015 14:19
Show Gist options
  • Save jcutrell/22a1da1ca068322ffb86 to your computer and use it in GitHub Desktop.
Save jcutrell/22a1da1ca068322ffb86 to your computer and use it in GitHub Desktop.
Weird behavior...
class BaseJob < ActiveRecord::Base
belongs_to :child_job, polymorphic: true
has_attached_file :header_image, :styles => { :medium => "800x500#" }
validates_attachment_content_type :header_image, :content_type => /\Aimage\/.*\Z/
validates :title, presence: true
validates :prompt_html, presence: true
end
class Redirector < ActiveRecord::Base
has_many :redirector_clicks
has_one :link_job
end
@jcutrell
Copy link
Author

This presented itself when I went to edit a link job, which is set up as a regular resource in rails. The form fields fill out properly. But the persisted? method doesn't return true, even though the link_job record has been persisted. This could be related to rails/rails#13744 - I haven't looked very far into this, as I'm expecting I'm doing something that is just a bad pattern and maybe we need to refactor our relationship between the base job and the link job, or something like that... Baffling, though, as that test passes all the way up to the final line.

@jcutrell
Copy link
Author

(The thing that led me to this was the fact that the form submission caused what looked like a duplicate record, but in fact was due to the form having the new link_jobs path set on it, then I tracked it down to the persisted method by looking at the form_for helper itself to determine which path it drops into resource forms.)

@jcutrell
Copy link
Author

As it turns out, the include BaseJobMethods line referenced a module that included ActiveRecord::Base. Removing that inclusion fixed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment