Steve Polito

Joined

2,270 Experience
20 Lessons Completed
0 Questions Solved

Activity

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

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.