Taylor Cooney
Joined
Activity
I haven't written the portion to parse the email and create the post, but I planned to model it around the logic here, Handling Inbound Email Parsing with Rails
Just updated the bottom of the thread Casey; needing some guidance on setting up the Conversation and Message between two different models.
I have a Store
object that has an email_address
attribute. Using the logic from and How To Build A Form and Handling Inbound Email Parsing with Rails, I'm trying to figure out how to structure a Conversation where a visitor can email the Store, and the Store can reply through email - their replies would post messages to the Conversation.
When a visitor inquires to the store (via form), I create a Reservation
record with their name and email, and start a Conversation
like this,
@conversation = Conversation.create(sender_id: self.id, recipient_id: self.store_id)
I wanted to model the notifications similar to this, where everyone but the sender receives an email, but I'm stumped on how to map the User, since it's two different objects (Reservation and Store):
def send_notifications!
(forum_thread.users.uniq - [user]).each do |user|
UserMailer.new_post(user, self).deliver_now
end
end
The Conversation model looks like this, may be wrong, any guidance on what I could use to make the messages unique and structure the notifications?
class Conversation < ApplicationRecord
belongs_to :sender, :foreign_key => :sender_id, class_name: "Reservation"
belongs_to :recipient, :foreign_key => :recipient_id, class_name: "Store"
belongs_to :reservation
has_many :messages, dependent: :destroy
end
The Message Post isn't fully fleshed out, not sure what to use to make it unique between the two Objects.
class Message < ApplicationRecord
belongs_to :conversation
validates_presence_of :body, :conversation_id
def send_notifications!
end
end
Posted in User Onboarding Progress Bar Discussion
Thanks for making this one Chris!
I'm having this problem too with a heroku deploy; anytime I refresh the page the cards disappear dispite the JSON data being rendered.
Posted in How to monitor account progress?
Is there any ETA on an episode like this?
You're correct @Monroe...I was getting an error with before_create
claiming that the referral code already existed
Posted in How to monitor account progress?
Interested
Still looking for some assistance here 😅
Has anyone had any success with Vue and ActiveStorage in the past? I could really use some assistance in refactoring the form to handle file uploads.
Hey GoRailers,
Stemming from the Rails & Vue.js Trello Clone, I'm looking to add file uploads to a Card model using the new Rails 5.2 ActiveStorage feature. I'm stronger in Rails - previously I would use Paperclip to handle this. I've setup the config/storage.yml
file and necessary migrations for ActiveStorage. I've also set the association between on the Card and updated the CardController
to permit files: []
.
The card.vue
component built from the tutorial currently works well; a Card can have a title and description, and the description can be updated. These records persist to the database. My problem is figuring out how to bind file uploads to the card, and the logic required to upload multiple files on save.
Currently I'm using <input name="files" type="file" data-direct-upload-url="/rails/active_storage/direct_uploads" direct_upload="true" />
to create the input field in the card. However, after selecting a PDF image from my local machine and clicking save, the logs show that nothing happens [in regards to inserting a new row in active_storage_attachments or creating a blob]. How can I expand the save method to accept the file? Is the input
field sufficient to bind the element?
card.rb
class Card < ApplicationRecord
has_many_attached :files
end
CardController
class CardsController < ApplicationController
private
def card_params
params.require(:card).permit(:list_id, :title, :position, :description, files: [])
end
end
card.vue
<template>
<div>
<div @click="editing=true" class="card card-body">
<h4>
{{card.title}}
</h4>
</div>
<div v-if="editing" class="modal-backdrop show"></div>
<div v-if="editing" @click="closeModal" class="modal show" style="display: block">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<div>
<h4>
{{card.title}}
</h4>
</div>
</div>
<div class="modal-body">
<div>
<h5>{{card.description}}</h5>
</div>
<textarea v-model="description" class="form-control"></textarea>
</div>
<div class="modal-footer">
<input name="files" type="file" data-direct-upload-url="/rails/active_storage/direct_uploads" direct_upload="true" />
<button @click="save" type="button" class="button button-secondary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
props: ["card", "list"],
data: function() {
return {
editing: false,
title: this.card.title,
description: this.card.description,
files: []
}
},
methods: {
save: function() {
var data = new FormData
data.append("card[title]", this.title)
data.append("card[description]", this.description)
Rails.ajax({
url: `/cards/${this.card.id}`,
type: "PATCH",
data: data,
dataType: "json",
success: (data) => {
const list_index = window.store.lists.findIndex((item) => item.id == this.list.id)
const card_index = window.store.lists[list_index].cards.findIndex((item) => item.id == this.card.id)
window.store.lists[list_index].cards.splice(card_index, 1, data)
this.editing = false
}
})
}
}
}
</script>
Posted in Using Webhooks with Stripe Discussion
I was able to simply add the signing_secret to config/secrets.yml, and in config/initializers/stripe.rb. My first deploy to heroku only added the signing secret to stripe.rb and was throwing an issue.
config/initializers/stripe.rb
Rails.configuration.stripe = {
:stripe_publishable_key => ENV['STRIPE_PUBLISHABLE_KEY'],
:stripe_secret_key => ENV['STRIPE_SECRET_KEY']
:stripe_secret_key => ENV['STRIPE_SECRET_KEY'],
:stripe_signing_secret => ENV['STRIPE_SIGNING_SECRET']
}class RecordCharges
def call(event)
....
Posted in Using Webhooks with Stripe Discussion
- Before requesting the job be performed, create the order record with a nil charge_id
- After the Stripe transaction has been completed in the job, update the order with the returned charge_id
Are any of these helpful to you?
I planned to move the Order.create call into the sidekiq worker and access the `charge.id` directly, but I can't access the @job within the worker because a stripeToken can't be used more than once. Any idea on how I can still save the `charge.id` to an `Order`? *(separate from the main Job model)*
JobsController
def create ... if @job.create_with_stripe(params[:stripeToken]) if @job.save Order.create( # Can't figure out how to pass the charge.id from StripePaymentJob :charge_id => @charge.id, :job_id => @job.id ) end ... end
Job Model
def create_with_stripe(token) Stripe.api_key = Rails.application.secrets.stripe_secret_key if valid? StripePaymentJob.perform_later(token, SecureRandom.uuid) else ... end
Stripe Worker
class StripePaymentJob < ApplicationJob queue_as :default def perform(token, idempotent_key) @charge = Stripe::Charge.create({ ... }, { idempotency_key: idempotent_key }) end end
That helps a bunch! I know I can disable retry support for a particular worker by appending:
sidekiq_options :retry => false # job will be discarded immediately if failed
Moreover, how are you setting the idempotency_key? Is it simple as setting it in the Object and it automagically works?
Chris, let me know if you have any insight on this with steps that I can implement.