Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
kayakyakr
Feb 16, 2004

Kayak is true
Yeah, Heroku is almost 0 effort and there are sooooooooo many guides on how to set it up.

You can even have heroku deploy automatically when you merge to a branch (eg merge to master). It's really quite nice.

Adbot
ADBOT LOVES YOU

Steely Dad
Jul 29, 2006



I'm working on a solo project using Rails with Docker, deploying to Heroku, mostly so I can get my feet wet with containers. My dev setup is basically having rvm and whatnot running natively on my Mac so I can run bundle and yarn to set up dependencies there, but only having a database instance inside my local container setup and only running tests and my dev server that way. I have no idea if this is a good way to do things. Any wisdom to share on developing locally with Docker?

Steely Dad fucked around with this message at 17:29 on Jul 28, 2021

kayakyakr
Feb 16, 2004

Kayak is true

Steely Dad posted:

I'm working on a solo project using Rails with Docker, deploying to Heroku, mostly so I can get my feet wet with containers. My dev setup is basically having rvm and whatnot running natively on my Mac so I can run bundle and yarn to set up dependencies there, but only having a database instance inside my local container setup and only running tests and my dev server that way. I have no idea if this is a good way to do things. Any wisdom to share on developing locally with Docker?

Totally a valid setup. Docker desktop has a beta feature available for development containers. VSCode can connect straight into those containers. You don't actually have to have any natively installed dependencies, it can all be in docker.

See more here:
https://docs.docker.com/desktop/dev-environments/

oliveoil
Apr 22, 2016

kayakyakr posted:

Totally a valid setup. Docker desktop has a beta feature available for development containers. VSCode can connect straight into those containers. You don't actually have to have any natively installed dependencies, it can all be in docker.

See more here:
https://docs.docker.com/desktop/dev-environments/

So I can have the same dev environment for my hobby projects no matter which PC I develop on WITHOUT any hassle to make sure I set them up the same?

That's awesome.

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

is docker sync still a thing

kayakyakr
Feb 16, 2004

Kayak is true

A MIRACLE posted:

is docker sync still a thing

Not really. Development containers makes it entirely pointless, as you can now develop directly on a docker container without having to sync local code to container code.

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

I would love some more info on that... Still using docker sync on an old project and it sucks. I have to restart it constantly because it won't pick up big version changes like files being removed etc. Or it just, forgets that it's supposed to be running sometimes and I'll be racking my brain trying to figure out why the build is wonky. Big rails 4 codebase via docker-compose on a Mac

edit, maybe using the nfsmount volume..? I'm gonna try some stuff today

A MIRACLE fucked around with this message at 19:43 on Jul 28, 2021

Tea Bone
Feb 18, 2011

I'm going for gasps.
I'm running an API server with rails. Calls to the server are made from app.mysite.com and mysite.com. The api runs from api.mysite.com

I've installed rack-cors and have the following config in my initializer:
code:
Rails.application.config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins 'mysite.local', 'mysite.com', 'app.mysite.local', 'app.mysite.com'
    resource '*', headers: :any, methods: [:get, :post, :patch, :put, :delete], credentials: true
  end
end
Everything works great on my local server. On the live server, I get the error:

quote:

The 'Access-Control-Allow-Origin' header has a value 'https://app.mysite.com' that is not equal to the supplied origin.
when I try and call the API from mysite.com. Oddly if I visit the API manually (i.e api.mysite.com/user.json) that seems to clear the error and everything works from mysite.com as expected.

I've tried replacing the origins array with a regex:
code:
/(.*\.)?mysite\.com/
But that gives me exactly the same error.
The only way I can successfully make the API calls from mysite.com is if I remove the subdomain references from the origins array completely.

I'm assuming I've misunderstood something fundamental about how rack-cors works.
Does anyone have any ideas?

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
I wonder if it could be a http/https thing. Is your local server http?

necrotic
Aug 2, 2005
I owe my brother big time for this!
You need the [url]https://[/url] included. I’m not 100% but without it my work for [url]http://[/url] (and seems like it did if it was working locally)

Tea Bone
Feb 18, 2011

I'm going for gasps.

Gmaz posted:

I wonder if it could be a http/https thing. Is your local server http?


Gmaz posted:

I wonder if it could be a http/https thing. Is your local server http?

Thanks guys. I finally got to the bottom of it. Chrome was caching the first Access-Control-Allow-Origin header, so whichever domain I made the first call from was stopping the second domain working. Looks like it was working locally because my local server wasn't including an ETag header, so no caching.

wolfman101
Feb 8, 2004

PCXL Fanboy
Anyone have an idea how to test whether null_session protection did something or not? https://github.com/rails/rails/pull/43760

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

Hey y'all. I'm working on a rails app for the first time in a while, trying to remember how eager loading works while writing a map / serializer json thingy and hitting mad N+1 queries on it

here's a really contrived example of what I'm trying to do

Ruby code:
class Person < ApplicationRecord
  has_many :person_organizations, dependent: :restrict_with_error

  has_many :organizations, through: :person_organizations

  scope :with_details, (lambda do
    includes(person_organizations: [:organization])
  end)
end
Ruby code:
Person.with_details.map { |p| puts p.organizations.map(&:external_reference_id) } # n+1 query  :(
please help me

edit... it seems like doing eager loading inside a scope doesn't work. invoking includes it outside a named scope works fine

edit, I'm actually just doing it wrong

A MIRACLE fucked around with this message at 23:26 on Apr 20, 2022

calusari
Apr 18, 2013

It's mechanical. Seems to come at regular intervals.
Ruby code:
Person.joins(person_organizations: :organizations).select('organizations.external_reference_id')
I think it is something like this

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
If you literally want just the external_reference_id and nothing else, pluck is better than select, so you don't have to hydrate the whole tree of objects.

Data Graham
Dec 28, 2009

📈📊🍪😋



Is there a general Ruby thread, or is this the closest thing?

The Y of my personal X-Y problem is "I'm trying to maintain Gitlab on FreeBSD, and Gitlab is a massive Ruby app and it isn't properly supported on FreeBSD except by one German guy who writes docs that don't quite work and doesn't reply to email".

Specifically I'm trying to run database migrations, and the rake command is failing because of missing gems, but I suspect they're missing because the maintainer guy didn't build the package properly, but again, he's not responding to email.

Does any kind goon have any experience in this sort of area?

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

post the error youre getting

Data Graham
Dec 28, 2009

📈📊🍪😋



I mean .. it's not a specific error, it's more like "does anyone have deep knowledge in reverse-engineering Gitlab and its database migrations".

The upgrade documentation I was following is here https://gitlab.fechner.net/mfechner/Gitlab-docu/blob/master/update/14.9-14.10-freebsd.md but it hasn't been responding for a few days, which is a great sign.

This is the page on Gitlab's docs that describes dealing with stuck batched migrations: https://docs.gitlab.com/ee/user/admin_area/monitoring/background_migrations.html#manually-finishing-a-batched-background-migration but it isn't directly applicable to FreeBSD (the docs from the mfechner site talked about "rake" instead of "gitlab-rake", etc).

I no longer have the commands in my history to try to rerun them and I can't do it from memory, but I was getting stuff like:

code:
.. fuckin ... I can't copy-paste out of WhatsApp which is where I had pasted my last error output to someone I managed to get to try to help me. Apparently WhatsApp doesn't have "copy" wtf

Anyway



Which I "solved" by installing the FreeBSD package of rubygem-rspec and manually adding that require statement; but then



So, yeah. What it all comes down to is that I feel like I'm the only person who's ever attempted this particular thing and everyone who could possibly help has vanished off the earth.

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home
That person's gitlab is down so I don't know what they're doing. Definitely sounds like you're missing some gem. If you could check the changes in the version you had to the version you're upgrading to, for Gitlab itself and this package, you could narrow it down.

Data Graham
Dec 28, 2009

📈📊🍪😋



Oh hooray, their site is finally back up:

https://gitlab.fechner.net/mfechner/Gitlab-docu/blob/master/update/14.9-14.10-freebsd.md

duck monster
Dec 15, 2004

Man. I've never had a really close look at Gitlab, but poking around it, its pretty loving good. Especially since Redmine feels so archaic these days.

Data Graham
Dec 28, 2009

📈📊🍪😋



The background migrations finally worked fwiw, after I waited for 15.0 to be packaged and ported and it fixed the stupid dependency issues.

But yeah, Gitlab is a staple at like three recent jobs, and now I have my own!

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home
That's good. Yeah, I ran Gitlab & CI Runner servers for my old job. Migrated em off a bare ssh only gitolite + trello + no CI at all to that and it was a huge win. Just used the omnibus package on an ubuntu lts vps and it rarely fussed. I'm sure plenty of sysadmins balk at that thing spawning a dozen different services, but it did Just Work.

Tea Bone
Feb 18, 2011

I'm going for gasps.
Is there a way to skip a file in the public directory?

Basically, I'm serving a react app from public/index.html which works great.
In development, though I'd like requests to hit my rails controller instead (so I can proxy the request to my local npm development server).
The trouble I'm having is if the index.html file exists in public then rails just automatically serves that and never touches the controller.

It's not a huge issue since I can just rename or delete the index file in development, but at some point I'm inevitably going to forget to add it back and push to live without it.

edit nevermind
config.public_file_server.enabled = false is what I wanted

Tea Bone fucked around with this message at 16:46 on Jun 30, 2022

KoRMaK
Jul 31, 2012



Maybe I am going crazy, but didn't the rails scaffold generator also create locale entries for you too?

...or maybe I programmed that myself and forgot?

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home

KoRMaK posted:

Maybe I am going crazy, but didn't the rails scaffold generator also create locale entries for you too?

...or maybe I programmed that myself and forgot?

I don't recall anything like this

Peristalsis
Apr 5, 2004
Move along.
I'm using the new delegated types feature in rails, and it seems interesting and functional, but I'm thinking about how we basically have two model objects for a single conceptual object now, and what to do about it. I was wondering if anyone else had any thoughts.

To use the example from the documentation:

code:
# Schema: entries[ id, account_id, creator_id, created_at, updated_at, entryable_type, entryable_id ]
class Entry < ApplicationRecord
  belongs_to :account
  belongs_to :creator
  delegated_type :entryable, types: %w[ Message Comment ]
end

module Entryable
  extend ActiveSupport::Concern

  included do
    has_one :entry, as: :entryable, touch: true
  end
end

# Schema: messages[ id, subject, body ]
class Message < ApplicationRecord
  include Entryable
end

# Schema: comments[ id, content ]
class Comment < ApplicationRecord
  include Entryable
end
The benefit is that you can construct a list of entries, and treat them all (more or less) the same. You can even display comments and messages in the same list if you have a partial for each, by using the entry.entryable_name method, something like this:

code:
<%= render "entries/entryables/#{entry.entryable_name}", entry: entry %>
The stated use case is making display and pagination of multiple, related types easier, and so far so good.

What happens when you want to retrieve a bunch of entries for something else, though? You get a collection of entries, each with an attached entryable object. You can access its associated entryable object to call methods and retrieve attributes from it, but you need to remember that the indirection is necessary. I've read some suggestions to delegate appropriate method calls on the Entry model to its entryable object, at least for methods defined in every delegated class, but I guess I'm a little surprised that something like that isn't baked into the mechanism.

And what about when you just retrieve a bunch of messages directly, without any comments, and without going through the Entry model? You have collection of messages, each with its associated entry object. But much, if not most, of the data for that message is actually on its entry object. So as you process your messages, you have an indirection issue to remember here, too. You could have the message model delegate the entry-related calls back to the entry, but it seems to me like an anti-pattern to have two classes where each is delegating to the other*.

Maybe the answer is to access messages and comments strictly through Entry - Entry.messages.where(...) and Entry.comments.where(...) instead of Message.where(...) and Comment.where(...) - and always remember that you have an entry object, rather than the associated delegated class. That probably works fine, but it seems unsatisfying to me. I guess my problem is that with all of this boilerplate, I should be able to treat the entry-entryable pair as a single logical object in the code. Otherwise, I'm not really gaining a lot over hand-rolling a solution.

Another issue that has come up is with has_many, through relationships with the delegated classes.
code:
user.rb

has_many: :entries_users, class_name: 'EntriesUser'
has_many: :entries, through: :entries_users
has_many: :messages, through: :entries
has_many: :comments, through: :entries
Some version of this works for retrieving comments or messages through their entries, but it requires a has_many, through built on top of another has_many, through. So, while I can access user.comments, rails understandably scoffs at user.comments << Comment.create(...).

I could add a many-to-many relationship directly between user and messages (and comments), and maybe that's the right answer, but then I either have to restructure some code that already uses the user-entry link (since I'm adding this to an existing project), or I have duplicate connections between each user and its messages (and comments), and have increased the potential for a data mismatch.

I don't know, I guess I just feel like this feature isn't quite ready for prime time, and that it should offer a little more convenience, or at least more documentation setting best practices for how to think of the resulting pairs of objects (i.e. do we now approach this as a bunch of entries with some delegated objects attached, or a bunch of messages and comments, each with some entry details attached?)


* Instead of delegation, I could use a method_missing method on one class telling it to go look at the other class before raising an exception, and that should be pretty equivalent.

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
I used it at my previous job few years ago (we actually backported into our Rails 6 application, because 6.1 was not released yet). It has its wonky parts but IMO still beats STI. I remember rewriting a couple of models from STI to delegated types and it really helped with maintainability.

quote:

You could have the message model delegate the entry-related calls back to the entry, but it seems to me like an anti-pattern to have two classes where each is delegating to the other*.
Yeah this is a bit wonky, but it works without any issues. So if you stomach it, conceptually what it does in the end is to give you a unified interface where you don't have to think about whether you're calling the parent or the delegated types.

quote:

Instead of delegation, I could use a method_missing method on one class telling it to go look at the other class before raising an exception, and that should be pretty equivalent.
I think they would implement it like this on the library level, if they were to do it. To me it's better to use the delegate_to because it's more explicit about which methods are being delegated.

quote:

how to think of the resulting pairs of objects (i.e. do we now approach this as a bunch of entries with some delegated objects attached, or a bunch of messages and comments, each with some entry details attached?)
It really depends on the context, in my case I had like 80% of situations where I didn't even need access to entryable object directly or have the need to call the specific delegate classes. In general if I were to use this again, I'd tend to go with the first approach. If I looked at it from the second approach then I would probably keep the models separated and create custom objects when I need to combine data.

Gmaz fucked around with this message at 16:25 on Mar 3, 2023

Peristalsis
Apr 5, 2004
Move along.
Thanks for your feedback. It's nice to have some confirmation at least that I'm not missing something easy and obvious.

Gmaz posted:

If I looked at it from the second approach then I would probably keep the models separated and create custom objects when I need to combine data.

Could you expand on what you mean by this, exactly? Do you mean you wouldn't use the delegated types construct at all, and just use regular composition, or you'd create another, separate class for handling merged entries and entryables?

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
Yeah, in that case I wouldn't use the delegated type at all. Usually this happens when data that's coming from a few models has some common attributes and needs to be presented in a combined way. In that case I'd use View objects, Presenters etc. whatever you want to call the pattern.

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

I have a service that is returning multiple headers with the same name and Faraday only adds one header to the response_headers per name. So it's keeping the first header and dropped the rest of them. guess I can try this in Net::HTTP

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

That sounds like it would suck for setting multiple cookies, weird.

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

I’m open to suggestions. I dug pretty deep into the gem with my debugger and can’t figure out a good place to monkey patch it. Or if I am doing it wrong. Was hoping to get it working in faraday cause I already built a whole library around it

A MIRACLE fucked around with this message at 00:34 on Jun 1, 2023

Pardot
Jul 25, 2001




Is it merging them down to a single one with commas? https://github.com/lostisland/faraday/issues/1120

prom candy
Dec 16, 2005

Only I may dance
Anyone out there still using Rails? I can't decide if I want to double down on my almost 20 years of experience with it and just ride out the rest of my career as a Rails expert or if I should delete it from my resume. It seems like there's lots of lucrative opportunities working on and modernizing legacy Rails apps but at the same time working on legacy Rails apps can be hell.

Sivart13
May 18, 2003
I have neglected to come up with a clever title
I've been using Rails on the backend for the last 10 years and would prefer to keep doing it. But it is somewhat limiting in that most similar webdev jobs seem to have node backends these days for some godawful reason.

I don't think it merits deleting from your resume though?

Gmaz
Apr 3, 2011

New DLC for Aoe2 is out: Dynasties of India
Why would you delete it from your resume even if you switch languages? At least for me experience is much broader than just using a programming language/framework, and a lot of concepts in software engineering are very much transferable.

As for Rails itself, it's been proclaimed dead for the last 7-8 years but I still see it kicking and new projects/startups being built with it, along with a couple of giants like Github and Shopify. If you like the framework and feel comfortable working with it, I see no reason to switch.

KoRMaK
Jul 31, 2012



i use computer to get things done. rails is great for getting stuff done.

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

I’m still doing rails and making good money at it. Node is good to know too, you can even cross over to .net if you want

Adbot
ADBOT LOVES YOU

prom candy
Dec 16, 2005

Only I may dance

Sivart13 posted:

I don't think it merits deleting from your resume though?

the problem with having it on my resume is i keep ending up in rails jobs. at my last job i joined as a frontend React dev but then it turned out i knew more about Rails than the backend team.

after getting into typescript i was kinda like "gently caress this i'm sick of all the indirection of rails I don't want to do this anymore" but i ran `rails new` for the first time in a long time last weekend and it is still an unbelievably fast way to build out ideas. where it choked for me was when i needed some stuff that React is good at, like a combobox. I've been doing Rails backend + React frontend for a long time but the call of the full on monolith is still quite appealing, especially with the growth of HTMX and everything talking about HATEOS and so on.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply