0

I have Recommendations has_many Approvals.

When one approval is made, the user provides an email address for the next user who needs to approve.

In my Approval Model

after_save :create_next_approval, :approval_notification


  attr_accessor :next_approver_email

  def recently_approved?
      self.approved_changed? && self.approved?
    end

    def create_next_approval
      #self.recommendations.create :email => self.next_approver_email if next_approver_email.present? && recently_approved?

      next_approval = self.recommendation.approvals.build(:email => self.next_approver_email)
      next_approval.save  if next_approver_email.present? && recently_approved? 
    end
 private
  def approval_notification
    ApprovalMailer.needs_approval(self).deliver
  end 

In the create_next_approval method, I am saving the next_approval. I am then sending an email to the next_approver_email address asking them to come approve the recommendation.

I am saving this approval here and I need to link to it in the email being sent out... any ideas?

TJ Sherrill
  • 2,465
  • 7
  • 50
  • 88

1 Answers1

0

If I follow you correctly. You need to link to the Approval that you just saved. So this would be self.

In that case something like this would work in your email if you have normal routes setup: <%= link_to "approval link", approval_path(self) %>

Let me know if I'm following correctly.

Stone
  • 2,608
  • 26
  • 26
  • my routes https://gist.github.com/1502681, and I didn't know I could call self in a view like that – TJ Sherrill Dec 20 '11 at 18:41
  • Yes, with those routes, TJ is correct. Because you're passing self to the view as an attribute of a method, it's available for your use. – Stone Dec 21 '11 at 07:09