Red Hendery

Joined

1,100 Experience
3 Lessons Completed
1 Question Solved

Activity

Is there a reason why we add the key to production.rb as opposed to application.rb like the docs say?

Posted in Sendgrid / Mailer Issue

Issue was being caused by a Click Tracking setting in SendGrid, URL's display correctly now but do not activate account in production. Heroku log below:

2021-04-04T17:28:35.393591+00:00 heroku[router]: at=info method=GET path="/" host=www.marincricketclub.com request_id=acdf2f79-632b-4732-9af4-a9578fe7b512 fwd="73.109.31.45" dyno=web.1 connect=0ms service=11ms status=200 bytes=5322 protocol=https
2021-04-04T17:28:35.383993+00:00 app[web.1]: I, [2021-04-04T10:28:35.383892 #4]  INFO -- : [acdf2f79-632b-4732-9af4-a9578fe7b512] Started GET "/" for 73.109.31.45 at 2021-04-04 10:28:35 -0700
2021-04-04T17:28:35.385055+00:00 app[web.1]: I, [2021-04-04T10:28:35.384970 #4]  INFO -- : [acdf2f79-632b-4732-9af4-a9578fe7b512] Processing by StaticPagesController#home as HTML
2021-04-04T17:28:35.386143+00:00 app[web.1]: D, [2021-04-04T10:28:35.386060 #4] DEBUG -- : [acdf2f79-632b-4732-9af4-a9578fe7b512]   Rendering layout layouts/application.html.erb
2021-04-04T17:28:35.386244+00:00 app[web.1]: D, [2021-04-04T10:28:35.386178 #4] DEBUG -- : [acdf2f79-632b-4732-9af4-a9578fe7b512]   Rendering static_pages/home.html.erb within layouts/application
2021-04-04T17:28:35.386830+00:00 app[web.1]: I, [2021-04-04T10:28:35.386749 #4]  INFO -- : [acdf2f79-632b-4732-9af4-a9578fe7b512]   Rendered static_pages/home.html.erb within layouts/application (Duration: 0.5ms | Allocations: 99)
2021-04-04T17:28:35.387808+00:00 app[web.1]: D, [2021-04-04T10:28:35.387718 #4] DEBUG -- : [acdf2f79-632b-4732-9af4-a9578fe7b512]   Rendered layouts/partials/_rails_default.html.erb (Duration: 0.7ms | Allocations: 220)
2021-04-04T17:28:35.389017+00:00 app[web.1]: D, [2021-04-04T10:28:35.388933 #4] DEBUG -- : [acdf2f79-632b-4732-9af4-a9578fe7b512]   Rendered layouts/partials/_navbar.html.erb (Duration: 1.0ms | Allocations: 273)
2021-04-04T17:28:35.389398+00:00 app[web.1]: D, [2021-04-04T10:28:35.389316 #4] DEBUG -- : [acdf2f79-632b-4732-9af4-a9578fe7b512]   Rendered layouts/partials/_footer.html.erb (Duration: 0.1ms | Allocations: 19)
2021-04-04T17:28:35.389527+00:00 app[web.1]: I, [2021-04-04T10:28:35.389440 #4]  INFO -- : [acdf2f79-632b-4732-9af4-a9578fe7b512]   Rendered layout layouts/application.html.erb (Duration: 3.3ms | Allocations: 819)
2021-04-04T17:28:35.389905+00:00 app[web.1]: I, [2021-04-04T10:28:35.389815 #4]  INFO -- : [acdf2f79-632b-4732-9af4-a9578fe7b512] Completed 200 OK in 5ms (Views: 3.9ms | ActiveRecord: 0.0ms | Allocations: 1223)
2021-04-04T17:28:35.529104+00:00 heroku[router]: at=info method=GET path="/packs/css/application-1ede7797.css" host=www.marincricketclub.com request_id=f7590cd2-5713-4d53-a226-51c9565508df fwd="73.109.31.45" dyno=web.1 connect=0ms service=3ms status=304 bytes=112 protocol=https

Posted in Sendgrid / Mailer Issue

Hello,

I run a website and I am having issues generating mailer links correctly, when a User signs up they must verify their email address. This all works as expected, mailer sends the email and it gets received.

The site is hosted on Heroku, when I view the logs they contain the route as I would expect, but in the email the link starts https://u9805564.ct.sendgrid.net which is tied to the Sender Authentication I was required to do.

Unsure what code is going to be helpful but happy to post anything requested.

#config/production.rb

  config.action_mailer.perform_caching = false
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.default_url_options = { protocol: 'https', host: 'marincricketclub.com' }

  ActionMailer::Base.smtp_settings = {
    :address        => 'smtp.sendgrid.net',
    :port           => '587',
    :authentication => :plain,
    :user_name      => 'apikey',
    :password       => ENV['SENDGRID_API_KEY'],
    :domain         => 'heroku.com',
    :enable_starttls_auto => true
  }

I am open to using a Sendgrid alternative, just needs to be cheap as we are going to send maybe 1000 emails a year.

Posted in How to create new contacts from nested attributes form

Is that the nested_attributes bit? Without seeing your code it's hard to say for sure, but you quite probably don't need to use nested_attributes, they'll just be adding unnecessary complexity.

I'm happy to look at your repo if you add redhendery to it on Github.

Posted in How to create new contacts from nested attributes form

Hey Seth,

You most likely don't need to use inverse_of, a correctly setup has_many_though association will give you access to things like Contact.signins or OpenHouses.contacts etc... Try:

Signin Model:
belongs_to :contact
belongs_to :open_house

Contact Model:
has_many :signins
has_many :open_houses, through: signins

OpenHouse Model:
has_many :signins
has_many :contacts, through: signins

Then check your signin migration, and makes sure you have:
t.belongs_to :contact, index: true
t.belongs_to :open_house, index: true

Let me know if you need any more help.
Red

You probably just need to add contact_id: [] to the signin_params.

Need to check your migrations as well and make sure you have your associations set correctly.

Suggest reading the Rails Guides on has_many_through
https://guides.rubyonrails.org/association_basics.html#the-has-many-through-association

You should also rename signin to viewings or something else. I would say the vast majority of people reading your code would think that the signin controller is for users signing in and not for what it actually does.

Sorry for the formatting of my post, I’m on a mobile device.

Posted in Is there a beginners course?

The Odin Project is a great place to start and if you're willing to pay for it, Michael Hartl's Rails tutorial is also excellent.

There are also loads of free lessons on Go Rails to get you started.

https://www.theodinproject.com/
https://www.railstutorial.org/