Rich Smith
Joined
Activity
Posted in Host PHP without breaking Hatchbox?
Hey Chris, any chance you can enable that on my account as well? I have two old client wordpress sites on an old server that I'd dearly love to shut down and move away from. Hoping to keep everything on one server going forward!
Thanks for that Chris! Have you looked into the Litestack Gem at all? Seems pretty neat!
How's it going? Any gotcha's worth sharing? Any special configs to getting it set up with hatchbox?
Thoughts on using something like Authentication Zero (https://github.com/lazaronixon/authentication-zero) in lieu of devise?
Hey Lee, did you ever figure this out? I am currently struggling with the exact same issue.
Posted in Using Webhooks with Stripe Discussion
Thanks for getting back to me! I am still struggling with this :/
Edit: Got it working but it feels dirty...
Here's what I have:
/config/intializers/stripe.rb
...
StripeEvent.configure do |events|
events.subscribe 'charge.succeeded', WebhookHandlers::StripeWebhookHandler.new
end
/app/services/webhook_handlers/stripe_webhook_handler.rb
module WebhookHandlers
module StripeWebhookHandler
class RecordCharges
def call(event)
...
end
end
end
end
Any chance you could point me in the right direction on wheather or not this is clean?
Posted in Using Webhooks with Stripe Discussion
Hey Chris,
I'm trying to figure out how to fix up my code and move the RecordCharges class out of my initializer and into a PlainOldRubyObjectâ„¢ located in app/services/webhook_handlers/stripe_webhook_handler.rb but am running into an issue that because the StripeEvent is called in an initializer (config/initializers/stripe.rb), the rest of the app isn't loaded so it is not able to call the class. Any chance you could help me out?
Thanks,
Rich
Posted in Stripe Elements Javascript Discussion
Hey Chris,
Running into a small issue with Rails 5.2 and Content-Security-Policy issues with the stripe elements.
Any suggestions?
I tried poking around config > initializers > content_security_policy.rb but changes such as the following didn't do much.
# Define an application-wide content security policy
# For further information see the following documentation
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
Rails.application.config.content_security_policy do |policy|
policy.connect_src :self, :https, 'http://localhost:3035', 'ws://localhost:3035' if Rails.env.development?
# policy.default_src :self, :https
# policy.font_src :self, :https, :data
# policy.img_src :self, :https, :data
# policy.object_src :none
policy.script_src :self, :https, 'stripe.com'
# policy.style_src :self, :https
# # Specify URI for violation reports
# policy.report_uri '/csp-violation-report-endpoint'
end
Posted in How do I apply a Pundit Policy to Index?
I'd like to have an index page show only the associated (from the parent, location) records, and allow only users that own those records to see the index. I am really struggling with this concept of scopes and would appreciate any help.
Here's where I'm at:
Models
User has_one :business has_many :locations, :through => :business end Business belongs_to :user has_many :locations end Location extend FriendlyId belongs_to :business has_one :user, :through => :business has_many :sites, dependent: :destroy friendly_id :custom_url, use: :slugged end Site belongs_to :location end
routes.rb
resources :locations do resources :sites end
sites_controller.rb
class SitesController < ApplicationController before_action :set_site, only: [:show, :edit, :update, :destroy] before_action :set_location, only: [:new, :show, :edit, :index, :update, :destroy] def index authorize Site @sites = @location.sites.all end private def set_site @site = Site.find(params[:id]) end def set_location @location = Location.friendly.find(params[:location_id]) end def site_params params.require(:site).permit(:location_id, :site, :url, :review_site_id, :number_of_reviews, :average_rating, :extra_data) end end
site_policy.rb
class SitePolicy < ApplicationPolicy class Scope attr_reader :user, :scope def initialize(user, scope) @user = user @scope = scope end def resolve if user.has_role? :admin scope.all else scope.where(location.user) end end end def index? return true if user.present? and user.has_role? :admin end ...
Any help or pointers at all would be super appreciated, I am really struggling wrapping my head around Pundit Scopes, but am keenly aware that I need them to get an index page to work.
Posted in How do I apply a Pundit Policy to Index?
Here's where I'm at:
# New Document
Here's where I'm at:
#### Models
```
User
has_one :business
has_many :locations, :through => :business
end
Business
belongs_to :user
has_many :locations
end
Location
extend FriendlyId
belongs_to :business
has_one :user, :through => :business
has_many :sites, dependent: :destroy
friendly_id :custom_url, use: :slugged
end
Site
belongs_to :location
end
```
#### routes.rb
```
resources :locations do
resources :sites
end
```
#### sites_controller.rb
```
class SitesController < ApplicationController
before_action :set_site, only: [:show, :edit, :update, :destroy]
before_action :set_location, only: [:new, :show, :edit, :index, :update, :destroy]
def index
authorize Site
@sites = @location.sites.all
end
private
def set_site
@site = Site.find(params[:id])
end
def set_location
@location = Location.friendly.find(params[:location_id])
end
def site_params
params.require(:site).permit(:location_id, :site, :url, :review_site_id, :number_of_reviews, :average_rating, :extra_data)
end
end
```
#### site_policy.rb
```
class SitePolicy < ApplicationPolicy
class Scope
attr_reader :user, :scope
def initialize(user, scope)
@user = user
@scope = scope
end
def resolve
if user.has_role? :admin
scope.all
else
scope.where(location.user)
end
end
end
def index?
return true if user.present? and user.has_role? :admin
end
...
```
Any help or pointers at all would be super appreciated, I am really struggling wrapping my head around Pundit Scopes, but am keenly aware that I need them to get an index page to work.
Thanks for all your help Chris!
Thanks so much for your help Chris! I really appreciate it.
One last question, when I'm building out forms, what would be the best way to have page-specific forms? Just create different views for specific pages?
Do you think something like this would work?
- User has_one business
- Business has_many :locations
- Location has_one :facebook_page, through => :review_sites
- Location has_one :google_page, through => :review_sites
- Location has_one :yelp_page, through => :review_sites
- ReviewSite belongs_to :location, has_one :yelp_page, has_one :google_page, has_one :facebook_page
- FacebookPage belongs_to :review_site
- GooglePage belongs_to :review_site
- YelpPage belongs_to :review_site
I'd prefer not having a messy models folder though, is something like [this](http://blog.hasmanythrough.com/2008/5/6/a-simple-alternative-to-namespaced-models) still an option in Rails 5.2?
My question is, should I keep all review sites in one big ugly model? Or should I namespace them and give each specific review site its own model? example models/review_sites/google_site.rb?
Posted in Best Method For User's Dashboard?
I was considering just generating a DasboardsController, but that doesn't seem very rails-y - for starts because of the fact that it is plural when in reality, it just needs to be DashboardController#index.
My app is set up in the following way:
Users
|
Businesses
|
Locations
| |
| Requests
Payments
OtherThings
I considered simply adding businesses#dashboard, but that seems wrong. I am trying to display chunks of info from children of the business model.
Any suggestions on design pattern here?
Cheers!