Paul Bernhard

Joined

120 Experience
1 Lesson Completed
0 Questions Solved

Activity

Posted in How to use Action Mailbox in Rails 6 Discussion

How come the mail and inbound_mail objects are available to all instance methods?

This question is not only related to ActionMailbox, but i will still post it here as i never saw a similar use of "local variables" before your episode on ActionMailbox, altough i am not sure if those are actually "local variables".

In your replies_mailbox.rb you have the following code:

class RepliesMailbox < ApplicationMailbox
  def process
    return if user.nil?
  end

  def user
    @user =|| User.find_by(email: mail.from)
        # the mail object is available here
  end

# …
end

Somehow the mail and the inbound_mail objects seem to be available to all instance methods of RepliesMailbox. This is an interesting functionality because you don't have to define all methods like def user(mail), def discussion(mail), def discussion_id(mail), if they all refer to the same mail object anyway.

I am not sure if the mail and inbound_mail are actually "local variables" and maybe i am missing out on a fundamental knowledge of variable scope. But how come you can access those objects throughout all methods? Can this way of "reusing" variables be used in all Ruby / Rails code?

Hi, thanks for this helpful introduction on ActiveStorage.
Does ActiveStorage provide a solution to process uploads on upload and not on-the-fly? For ex. processing video-files could be time-consuming and good to be done on upload.
If there is no option to process on upload, is there a reason to prefer on-the-fly processing?