Dan Tappin

Joined

8,170 Experience
0 Lessons Completed
9 Questions Solved

Activity

Posted in Bizarre cache issue

How do I force the browser to always refresh parts or all of the content?

I have a bizzare issue where the browser is caching parts of the site. For example I have a 'History' for a model row in the DB. I add a comment, update etc. If I visit the History page then navigate to another action that adds a history then return to the history page it is the old version. If I refresh I get the new content. I am now finding these issues everywhere in my site.

I can confirm that there are no hits to the server so it's not a Rails caching issue - seems to be browser based.

Any ideas?

I have a Rail app where the user can switch tenants (activerecord_acts_as_tenant). The issue is that in production the browser is caching the old client HTML etc.

I came across this:

https://stackoverflow.com/questions/49547/how-do-we-control-web-page-caching-across-all-browsers

headers["Cache-Control"] = "no-cache, no-store, must-revalidate" # HTTP 1.1.
headers["Pragma"] = "no-cache" # HTTP 1.0.
headers["Expires"] = "0" # Proxies.

I have a controller that sets a session variable and then redirects to root. I want to 'reset' the cache etc. at this point but I can't seem to figure out how to implement this.

It's very bizzare. The browser keeps the old HTML even over manual refreshes. Tried again this morning to have the site even load the page after Devise had timed out. The datatables failed as they were calling JSON from the live site but authentication failed so they throw errors.

Posted in Multitenancy with the Apartment gem Discussion

I guess I should have been clearer - I have a SSO type system with an 'enrollment' between the tenant and the user (the same user can access multiple tenants with a single login). The enrollment holds the tenant information.

My thought is to just store the tenant name in a session variable. Then I can switch the enrollment and then the app controller can switch the tenant based on the stored session.

Posted in Multitenancy with the Apartment gem Discussion

Question - how are you setting the tenant? Just saving a simple session variable with the tenant name?

Posted in Multitenancy with the Apartment gem Discussion

I am seriously considering switching now. When the developers of Apartmment say don't use Apartment that is a sign lol

Posted in Polymorphic Search

I have a basic model structure like this:

class History < ActiveRecord::Base
  belongs_to :historical, polymorphic: true, touch: true
end

with several related models:

has_many :history, :as => :historical, :dependent => :destroy

It seem to me that there is no easy way to search the History model AND the related models. For example each related model has a name and notes field. Can I do some sort of crazy multiple join and use conditions on the join?

Posted in Sub-site Authentication? (FAQ / KB / Helpdesk etc.)

Getting close:

    # routes.rb

  authenticated :user do
    get '/help', to: redirect('https://help.insertyour.domain'), as: :help
  end

  unauthenticated do
    get '/help', to: 'home#dashboard'
  end

This solves the redirect but created another issue. The help site sends you to the main site (https://app.insertyour.domain/help) signup page. You authenticate and then devise sends you back to the help site and it allows access. The problem is that if you go back to the main app you have to authenticate again. It's not idea but works for now. Not sure why a new attempt to access the main site requires authentiction again.

Posted in Sub-site Authentication? (FAQ / KB / Helpdesk etc.)

That was perfect - I still need to sync the users but for now it's gold. Here is what I did:

  • used the same secret access key on both apps
  • added :domain => ".insertyour.domain)" so the session_store.rb directive
  • on my helpy deploy I added an application before_action: redirect_to 'https://app.insertyour.domain/help/' if session[:enrollment_id].nil?
  • on my main app routes I have: get '/help', to: redirect('https://help.insertyour.domain'), as: :help

The idea here was that if you hit the help site not authenticated you get redirected to the main app help path, Devise would authenticate then send you back to the help site. The issue is that I now get a ERR_TOO_MANY_REDIRECTS error. Any ideas on how to make this work?

Posted in Sub-site Authentication? (FAQ / KB / Helpdesk etc.)

Back to the cookies idea. I synced the key base. I want to start with setting an expiring cookie on the main app then confirming in Helpy that it's set. If not redirect to the main app. I will add the Devise synce later.

I tried setting a cookie on the main app then displaying the contents in Helpy but no dice. Any pointers?

Posted in Sub-site Authentication? (FAQ / KB / Helpdesk etc.)

Yup - ran the seed file and all was good.

FYI - Hatchbox makes these deploys painless. If the seed had not failed I would have had Helpy deployed from scratch in 10 minutes. 👍

Posted in Sub-site Authentication? (FAQ / KB / Helpdesk etc.)

I downloaded the repo locally and fired it up. The onboarding page asks you info and sets up the first user etc. (like WordPress does etc.). I the pushed this to my GH account and deployed in my Hatchbox account and deployed. It looks like the seedfile didn't run. Going to try and run that manually...

Posted in Sub-site Authentication? (FAQ / KB / Helpdesk etc.)

Chris - any tips to deply Helpy? I am hitting this issue:

https://github.com/helpyio/helpy/issues/1517

onboarding_controller.rb in index at line 8

onboarding_controller.rb:8:in `index'

  def index
    @user = User.first
    @user.name = ""
    @user.email = ""
    @user.password = ""
  end

Posted in Sub-site Authentication? (FAQ / KB / Helpdesk etc.)

Thanks - I will give that a try and post my results 👍

Posted in Sub-site Authentication? (FAQ / KB / Helpdesk etc.)

I was looking at helpy.io which looks like it uses Devise. Any tips / pointers on syncing the two databases?

Posted in Sub-site Authentication? (FAQ / KB / Helpdesk etc.)

Does anyone have a suggestion to integrate your main Devise based Rails app with a secondary related site?

In my example I have a standard Rails app behind authentication with Devise. I want to also have a separate support / knowledge base site behind the same authentication (i.e. single sign on). It would look like this:

  • app.mysite.com (main site - user login)
  • help.mysite.com (sub site - user has access when currently logged into the main site)

I was thinking that it would be some sort of OMNIAuth or LDAP but could it be as simple as an encrypted token in a cookie? If you don't have that cookie set you just get a redirect to the main site login page? Thoughts?

Posted in Multiple File Uploads with a nice JS interface?

Two reasons - if you have a wreck you cant easily find ophaned files.

I also have clients than need data segrigation.

Dan

Posted in Multiple File Uploads with a nice JS interface?

I am going with an 'Attachment' model which belongs to other models (just one for now).

The 'Attachment' model to add other fields and funtionality down the road. Each record has one file uploaded against it.

I started with ActiveStorage but am abandoning that because AS just dumps all your files into the root of your filestore. So down the road when I have a million uploads I have a mess. Carrierwave (and other gems) let you organize your uploads into organized directories etc.

I am currently just using a nested form and ActiveStorage in my edit view. It works but is clunky. I wanted to use Dropzone (as I used a few years back) but it doesn't seem to support nested attributes.

Is there a modern and easy to use combination of gems / JS to do this based on my set-up?

Thanks,

Dan

I created a secondary model Attachments to add has_attached to so I could add additional fields. The issue is that there no easy way to validate the presence of an attachment. Also when my validation on the other fields fails the previously uploaded file does not seem to persist to the render :edit page.

Posted in Direct Uploads with ActiveStorage Discussion

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.