Vito Botta

Joined

2,850 Experience
20 Lessons Completed
1 Question Solved

Activity

In case others need this, I found this gem, it can sort by array of ids with a native SQL query and return a relation.

https://github.com/khiav223577/find_with_order

Hi, @chris I am having this problem now trying to decide if to use ActiveStorage. If I go with your second option (I will have attachments in various places, and I think I will need sorting only in one case), what's the easiest/most efficient way of sorting the images by the given array of ids? Thanks!

Posted in Sorting Images using Active Storage

I'm also interested. Thanks in advance

Posted in How to use Multiple Databases in Rails 6.0 Discussion

Hi. I am trying to use Rails 6's automatic read/write splitting with the multiple databases feature. There seems to be a problem with Devise, because the automatic connection switching sends writes to the master for POST/PUT/DELETE requests and reads to the replicas for GET requests. However Devise makes changes/writes to the database even with GET requests sometimes (for example to confirm a user upon sign up using a token in the link in the confirmation email), so these changes are basically blocked by Rails. Does anyone have any idea for a workaround? I've opened a Github issue about it: https://github.com/plataformatec/devise/issues/5133

Thanks!

Nevermind. The redirection does work and the confusion came from the fact that Chrome/Brave/Safari hide the "www" part of the address. Not sure when this change was made. Firefox still shows the "www".

Uhm I just noticed using that puts command that the subdomain appears as "www" already so the redirection doesn't happen. But I am definitely visiting the website with the naked domain ?!

Hi, I am trying to force a redirect from naked domain to www from inside the Rails app, since I can't do this with the Nginx ingress in Kubernetes (basically, users can add custom domains and the app itself does some redirect depending on the domain etc, so long story short I cannot force the same redirect for all the requests using Nginx).

I am using a constraint to my routes.rb that checks if the request is for the naked domain, and if that's the case it redirect to the same path but with the www subdomain.

The constraint:

class Constraints::NakedDomain
  def self.matches?(request)
puts request.subdomain
    (request.host.downcase == Settings.domain) && (request.subdomain == "")
  end
end

In routes.rb:

  constraints(Constraints::NakedDomain) do
        get ':any', to: redirect(subdomain: 'www', path: '/%{any}'), any: /.*/
  end

I can see the www domain in the Network tab of the Dev tools in Chrome, but the domain in the address bar of the browser remains the naked domain. Is it because of Turbolinks? Does anyone know how to fix or anyway how to force redirection to www from inside Rails instead of the web server? Thanks!

Right, it wouldn't make sense :)  I was wondering mainly about automated deployments - i.e. how does the app know which passwords to use when doing things on servers if passwords are encrypted. But I was now reading about attr_encrypted and similar, would that be a good enough approach to encrypt sensitive information? Thanks!
Cool. Out of curiosity, when creating servers and apps, are the passwords stored in clear in the database? 

Posted in Sortable Drag and Drop Discussion

Another question.... how would you go about testing sorting with Capybara/system tests? Thanks

Posted in Sortable Drag and Drop Discussion

Update: actually... it seems to work just fine. The two requests update the two lists correctly with no other changes. Thanks! :)

Posted in Sortable Drag and Drop Discussion

Hi Chris, I would need to be able to sort items in a list as you've shown in this episode, but also move items between linked lists. How would you implement this? Problem is that in this case I need to remove the item from the old list and add it to the new list, besides updating the positions, and the new positions should be correct in both lists without leaving gaps in any of them. So I guess the serialize trick and just updating positions in batch in the controller would not be enough? I also noticed that when you move an item from a list to another, jQuery UI Sortable triggers two update events, one for the source list and the other for the destination list. Thanks a lot in advance for your help!