Skip to content

Commit

Permalink
Add callback to create card after listing creation
Browse files Browse the repository at this point in the history
  • Loading branch information
0xifis committed Jun 18, 2018
1 parent 22d0154 commit 717f276
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/admin/listings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
@lists = List.sorted
end

permit_params :tenant, :postcode

end
11 changes: 11 additions & 0 deletions app/models/listing.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
class Listing < ApplicationRecord
has_one :card

after_create :create_card

private

def create_card
list = List.where(position: 1).first
list.cards.create({
listing_id: id
})
end
end

0 comments on commit 717f276

Please sign in to comment.