Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 Action Mailer Previews and Factory Girl issues

I've been running into quite an annoying issue when dealing with Rails 4 action mailer previews and factory girl. Here's an example of some of my code:

class TransactionMailerPreview < ActionMailer::Preview
  def purchase_receipt
    account = FactoryGirl.build_stubbed(:account)
    user = account.owner
    transaction = FactoryGirl.build_stubbed(:transaction, account: account, user: user)
    TransactionMailer.purchase_receipt(transaction)
  end
end

This could really be any action mailer preview. Lets say I get something wrong (happens every time), and there's an error. I fix the error and refresh the page. Every time this happens I get a:

"ArgumentError in Rails::MailersController#preview A copy of User has been removed from the module tree but is still active!"

Then my only way out is to restart my server.

Am I missing something here? Any clue as to what is causing this and how it could be avoided? I've restarted my server 100 times over the past week because of this.

EDIT: It may actually be happening any time I edit my code and refresh the preview?

like image 919
Greg Blass Avatar asked Aug 20 '15 12:08

Greg Blass


1 Answers

This answers my question:

https://stackoverflow.com/a/29710188/2202674

I used approach #3: Just put a :: in front of the offending module.

like image 95
Greg Blass Avatar answered Jan 09 '23 09:01

Greg Blass