Mark

Joined

1,830 Experience
10 Lessons Completed
1 Question Solved

Activity

Posted in New website design!

Quick addendum, found this great resource on learning Alpine.js too:

https://scrimba.com/learn/alpinejs/introduction-cV8mRBsp

Posted in New website design!

Hi Chris,

I was curious if you're considering doing a video on how to implement Alpine.js or Stimulus with TailwindUI?

I just purchased TailwindUI to help get my current application up and running and now I'm digging into figuring out how to use either Alpine.js or Stimulus to implement the functionality of the designs — and would certainly love any guidance from a video of yours.

Thanks either way and looks great!

Posted in How to Add Pagination with Pagy Discussion

Thank you Chris, for another awesome and clear explanation. And thank you Domizio for making Pagy.

👏

Chris helped clarify what I was doing wrong, thank you Chris!

I ended up with this in my mailer:

def new_post_notification
    @post = params[:post]
    @recipient = params[:recipient]

    mail(to: @recipient.email, subject: "My subject")
  end

Posted in Setup noticed to send emails through a mailer?

:) Thank you Chris!

Posted in Setup noticed to send emails through a mailer?

Hi Chris,

Sorry, I didn't "notice" (a lot to unpack here about my notice abilities) that you had a dedicated section for questions:

I was wondering how you configure your Noticed gem to work with mailers.

I had setup my post_controller to use the NewPostNotification.with(post: @post).deliver_later(Audience.all), where Audience is the model instead of the User model.

From my Posts controller

```ruby
def create
    @post = current_user.posts.build(post_params)

    respond_to do |format|
      if @post.save
        NewPostNotification.with(post: @post).deliver_later(Audience.all)
        format.html { redirect_to @post, notice: 'Post was successfully created.' }
        format.json { render :show, status: :created, location: @post }
      else
        format.html { render :new }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end
 ````

From my mailer

```ruby
def new_post_notification
  @post = params[:post]
  mail(to: @post.recipient, subject: "My subject")
end
```

From my NewPostNotification class

class NewPostNotification < Noticed::Base
  # Add your delivery methods
  #
  # deliver_by :database
  deliver_by :email, mailer: "AudienceMailer"
  # deliver_by :slack
  # deliver_by :custom, class: "MyDeliveryMethod"

  # Add required params
  param :post

  # Define helper methods to make rendering easier.
  #
  def message
    t(".message")
  end

  def url
    post_path(params[:post])
  end
end

I'm currently getting an error: NoMethodError: undefined method `recipient' for nil:NilClass . This makes me think that, well there's not recipient method on my @post, but that ultimately I'm not passing the information from the notification to my mailer method correctly, but I'm struggling to figure that out at the moment.

Thank you.

Best,
Mark

Hi Chris,

Thanks for this gem and tutorial!

With that said, I'm struggling to understand how to pass it to my mailer method.

I'm getting this error that says: ArgumentError: wrong number of arguments (given 0, expected 2..3) for my mailer.

In my mailer, I have a method, new_post_notification, named after my notification class NewPostNotification.

The method is defined as:

def new_post_notification
@notification = notification

mail(to: @notification.recipient.email, subject: "My subject here")

end

And in my posts_controller I have this:

def create
@post = current_user.posts.build(post_params)

respond_to do |format|
  if @post.save
    NewPostNotification.with(post: @post).deliver_later(Audience.all) # Here's where I inserted the notification code
    format.html { redirect_to @post, notice: 'Post was successfully created.' }
    format.json { render :show, status: :created, location: @post }
  else
    format.html { render :new }
    format.json { render json: @post.errors, status: :unprocessable_entity }
  end
end

end

Per the error, my thinking is that I need to add parameters to my new_post_notification mailer method:

def new_post_notification(notification, recipient, options={})
@notification = notification

mail(to: @notification.recipient.email, subject: "My subject here")

end

But, that didn't work either and had the same error message. I realize I am definitely not doing this right, and I am pretty new to Ruby and Rails, so I definitely think I'm going 'round in circles missing the obvious.

Thank you.

Posted in Direct Uploads with ActiveStorage Discussion

Great episode, thanks again Chris!

Amazing episode, thank you Chris!

Posted in Using mail_form gem and Sendgrid - having an issue

I was experiencing something similar after following a mail_form tutorial. In my case, the email wasn't being sent through due to DMARC and spam prevention practices from Sendgrid (and settings I setup to help thwart spammers). So, this is actually good behavior but I still want the email to be sent.

I solved this by changing this :from => %("#{name}" <#{email}>) to :from => "email@myallowedemailingdomain". I then added an interpolation to the subject line to give a little clarity on who the email is from before opening it.

For example, :subject => "Contact Form #{name}".

So, about three steps:

1) Setup an email address to send yourself emails from your domain (contactmailbot@mydomain.com)
2) Change :from => %("#{name}" <#{email}>) to :from => "contactmailbot@mydomain.com"
3) Optional: add string interpolation to your subject header portion for more info (:subject => "Contact Form #{name} | My Website").

Hope this helps.