Steve Polito

Joined

3,710 Experience
34 Lessons Completed
0 Questions Solved

Activity

Posted in Issue with Nested Forms in Rails 6.1.3.2

I think the main problem was that you were calling @client.shipping_addresses.build in multiple places, so the values from the form were probably getting overridden.

  • Remove @client.shipping_addresses.build(client_params[:shipping_addresses_attributes]) and @client.save and from ClientControllers#create.
  • Remove autosave: true from has_many :shipping_addresses from the Client model. I'm not sure if that was also causing an issue or not.
  • Replace @client.shipping_addresses.build with :shipping_addresses in app/views/clients/_form.html.erb.

I made a PR against your repo that should solve the problem

https://github.com/cjmccormick88/testapp-nested/pull/1

Posted in Issue with Nested Forms in Rails 6.1.3.2

Is this the link to your application? I might be able to take a look and submit a PR.

https://github.com/cjmccormick88/testapp-nested

Posted in GoRails Performance - The Techniques I Use Discussion

I’m watching this for the first time now (in 2021) and it’s awesome to see how spot on Chris is with his use and recommendation of Turbolinks.

This is so much easier to implement compared to using a front end framework like React. I wish I knew about these concepts earlier!

This is super slick. I wonder how easily one could append the query parameter in the URL to reflect the current page? Could History.replaceState() handle the job?

Posted in How is the Front End of GoRails Built?

Oh dang, didn't realize Turbolinks is that fast. I've only made 2 production apps in Rails, and never realized this happened out of the box. Sick!

Posted in How is the Front End of GoRails Built?

The new site is screaming fast. I notice that there's no page refresh on almost all requests. Is this View? React? Something else? I'm curious to know how this is done.

Problem

I am getting the following console error on a form using cocoon. However, on page refresh the error is gone and the form works.

js.stripe.com/:1 Failed to execute 'postMessage' on 'DOMWindow': The target origin provided 
('https://js.stripe.com') does not match the recipient window's origin ('http://localhost:3000')

I am loading stripe in the head <%= javascript_include_tag 'application', 'https://js.stripe.com/v3/', 'data-turbolinks-track': 'reload' %>.

Things I Tried

  • When I removed //= require turbolinks from application.js, that solved issue.
  • When I added <body data-turbolinks="false"> to the body, that solved issue.
  • However, when I conditionally added <body data-turbolinks="false"> to the /new and /edit routes in question, that DID NOT solve the issue. My guess is that I need to disable turbolinks on another route or action in the app, but just not sure what that would be.

Problem

I have an event that starts Jan 1, 2017 and repeats every day until Dec 31, 2017. If I search for an event (using ransack) that starts after Jan 1, 2017 no events will appear, because the only record saved to the database has a start date of Jan 1, 2017. The rest of the records are created in memory. However, if I search for an event that starts before Jan 1, 2017, all results render as expected.

Setup

I have a list of repeating events. The repeating events are created using ice_cube and recurring_select, along with the following method in my model.

event.rb

    ...
def events_list(start)
    if recurring.empty?
      [self]
    else
    end_date = start.end_of_year
      schedule(start_time).occurrences(end_date).map do |date|
        Event.new(id: id, title: title, start_time: date, club: club)
      end
    end
  end
    ...

events_controller.rb

...
def all
      @q = Event.ransack(params[:q])
      @events = @q.result(distinct: true).order(start_time: :desc)
      @events_list = @events.flat_map{ |e| e.events_list(params.fetch(:start_date, Time.zone.now).to_date) }
      @events_list_paginated = @events_list.paginate(page: params[:page])
end
...

Posted in Recurring Select Accepts "Null" As a Valid Rule

I followed the Chris' excellent tutorial on Recurring events with the ice_cube gem. However, I was running into an issue when the value of recurring was set to - not recurring -. If I went to create or update an event, I would get the following error:

undefined method 'to_hash' for nil:NilClass, which pointed to this line super(RecurringSelect.dirty_hash_to_rule(value).to_hash)

The actual value of this field is null, and for some reason this value was being accepted as a RecurringSelect.is_valid_rule?.

I ended up rewriting my recurring= method to the following to solve the issue.

  def recurring=(value)
    if value == "null"
      super(nil)
    elsif RecurringSelect.is_valid_rule?(value)
      super(RecurringSelect.dirty_hash_to_rule(value).to_hash)
    else
      super(nil)
    end
  end
  1. Is my solution acceptable?
  2. Any reason why I'm running into this issue? Is it because I'm running a different version of Rails? I'm on rails 5

Posted in Email Stripe Receipts

Firstly, thanks for the great Stripe tutorials! I just finished implimenting basic subscriptions on my rails app. However, I do have a few questions regarding emails.

Will Stripe automatically email a receipt to the customer upon each charge.succeeded event? Or, do I need to impliment this on my end via Webhooks?

If I need to do this via Webhooks, would I do something like the following?

class RecordCharges
    def call(event)
        ...
        SubscriptionMailer.charge_succeeded.deliver_now
        ...
    end
end

StripeEvent.configure do |events|
  events.subscribe 'charge.succeeded', RecordCharges.new
end