|
GeorgieMordor posted:Totally. Request tests should be more than adequate, especially since this is an API app anyway. I was just running through some RSpec refresh and thought I'd give the controller tests a go just for sharpness' sake. Historically controller tests were used to ensure that certain instance variables were set in the controller before rendering any sort of views and it made it easier to retrieve values that were created/updated. Multi-mode servers have gone out of favor and feature and request specs cover the use cases better most of the time.
|
# ¿ Feb 20, 2019 00:52 |
|
|
# ¿ May 16, 2024 00:55 |
|
Fastest freeform I've worked with was Grape::Entity. Was using it in a normal rails API app, not with Grape.
|
# ¿ Mar 6, 2019 16:54 |
|
Tea Bone posted:I’m trying to set up a relationship from a record to records it isn’t associated with. Imagine the following: code:
code:
If you're looking to fill out a list of books on each reader's non-books array, well, I think that the N+1 may be the best you can get because rails has to break that down to apply it to the object anyway.
|
# ¿ May 15, 2019 17:44 |
|
Piano Maniac posted:Rails gurus, I am in a dire need of your help. https://www.rapidtables.com/web/html/link/html-anchor-link.html basically, if you're putting the # in front of the ID on the target, then you're doing it wrong.
|
# ¿ May 22, 2019 15:15 |
|
necrotic posted:Integration tests aren't, which go through the request flow. Testing the controllers directly is indeed deprecated, test the routes. rspec broke controller tests a long, long time ago. They're still possible, but pretty hard with the newest versions. Mostly integration tests with a few model unit tests thrown in for good measure is the way to go.
|
# ¿ Jul 11, 2019 14:54 |
|
ddiddles posted:This is awesome, thanks for all that info. I've been really impressed with Cypress for front-end integration testing.
|
# ¿ Jul 11, 2019 16:24 |
|
ddiddles posted:Another question about rails specs. Switched over to using request specs rather than controller, but I'm repeating myself a lot checking that routes are protected by auth. You could also do: https://relishapp.com/rspec/rspec-core/docs/example-groups/shared-examples
|
# ¿ Jul 20, 2019 02:40 |
|
GeorgieMordor posted:I'm using FactoryBot in my test cases. How do I create a related record that can be referenced multiple times in a single factory? For instance, instead of using association :owner in a :car factory, I'd create the :owner record first and then explicitly define it's properties in the :car factory. Example of what I thought might work: So, there are definitely ways of doing this, yes, but... why are you denormalizing your database like this? Use a join or an include to get that information from the DB, don't save (and then have to sync) it to the model.
|
# ¿ Jul 23, 2019 15:17 |
|
GeorgieMordor posted:Also my thoughts, though this is a legacy application I've been brought on board for so I'm at the mercy of the current functionality. At least for now. You'd use after hooks to do this. From way back in the factorygirl days: https://thoughtbot.com/blog/aint-no-calla-back-girl
|
# ¿ Jul 23, 2019 15:36 |
|
Awesome Animals posted:You could also probably use a let! Or actually, could use factorybot's version of this, the transient: https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#transient-attributes
|
# ¿ Jul 23, 2019 21:35 |
|
DaTroof posted:Overriding an existing method is heinous because it can lead to incorrect assumptions and elusive bugs. Adding new methods to an existing class isn't as bad. Given that Rails is already a quilt sewn from monkeypatches, adding a couple String methods seems okay; but my first preference would still be to encapsulate those features in a dedicated class or module, especially if the implementation requires internal state. Good response. GeorgieMordor posted:I'm working through a Rails update now. Pre-existing Rails 4.2.* app to 5.2.3. I think that's coming from the original requester. That's a string being encoded and wrapped as another string. So the request is being sent like: post('endpoint', { json: JSON.stringify(someJson) }) Right? So that happens with a lot of libraries (I think including jquery) when you don't provide a content type with the ajax post. They automatically encode things as strings and don't leave them as JSON. Only thing I can think of with Postman is that you're actually posting unparseable JSON for one reason or another.
|
# ¿ Jul 25, 2019 22:37 |
|
Rails 6 went official yesterday: https://weblog.rubyonrails.org/2019/8/15/Rails-6-0-final-release/
|
# ¿ Aug 16, 2019 20:07 |
|
The Journey Fraternity posted:I would love to, if it weren't such a behemoth undertaking even to get it to 5.0. This codebase predates every single engineer, and was originally written by PHP devs writing their first Rails app. 1) you do need a new job 2) I don't have much empathy, at least for your company, because you didn't spend any time maintaining your codebase. If you had followed along with rails versions, it wouldn't be such a massive undertaking. The longer you put it off, the more painful it will become. Also, Rails 4 to rails 6 isn't so hard. The codebase was mature enough by Rails 4.2 that there aren't many barriers to changing over.
|
# ¿ Aug 19, 2019 15:26 |
|
duck monster posted:Unpopular opinion, but yes. Ditto with Node JS. The jobs have been drying up as companies move across to python, and a LOT of pretty important libraries seem abandoned now. I disagree. I think Rails is holding steady as a fantastic low-risk language for startups and I found plenty of jobs out there for senior devs. It's biggest competitor is not python, but instead NodeJS which is still getting a lot of new startup work. I feel that Python is tending to carnivorize more and more of Java and Microsoft's markets. Depending on which metrics you track, Ruby's been up or at least holding steady YoY. There are some old libraries that seem abandoned, but I prefer to think of them as "mature"
|
# ¿ Sep 15, 2019 02:56 |
|
Edgar Allan Pwned posted:so im working on a coding practice, using an api for a random name and another api for a random joke. im supposed to be able to create an api that generates this new joke on create. it will be tested by using curl. You can either use a service pattern or a before_create callback. You can also make a fat controller because WGAF and call out to the API there. Depends on what all is involved in generating a new joke. Is it calling a separate api? Is it calling a machine learning algorithm? Asking a contractor overseas?
|
# ¿ Nov 15, 2019 00:03 |
|
I'd probably build it wherecode:
|
# ¿ Jan 14, 2020 18:06 |
|
Tea Bone posted:Thanks guys. I ended up flipping the relationship (so that suit belonged to card) as it made more sense for my use case and that ended up solving the issue. So you have... 4 suits per card and 13 suits per deck? Interesting setup indeed...
|
# ¿ Jan 15, 2020 16:14 |
|
Jaded Burnout posted:I've been working with Rails for a very long time, and I have a new side project I'd like to do that's very data input heavy, and I absolutely cannot face setting up all the controllers and such. Is there a nicer way to do it than either grinding through it or using the scaffolding generators? Anything nice and dynamic that doesn't immediately fall apart? I mean, are you looking for admin interfaces like rails-admin? Or are you looking for, say a CMS backend like Contentful or Kentico? Or, if you need to roll something yourself, this looks like a fun way to get a quick data server going and being GraphQL it's decidedly NOT rails: https://evilmartians.com/chronicles/graphql-on-rails-1-from-zero-to-the-first-query
|
# ¿ Feb 26, 2020 23:13 |
|
Rubymine is a good all-in-one IDE. Personally, I use vscode and separate terminals.
|
# ¿ Sep 15, 2020 16:07 |
|
I have a dream of rails meets JS like https://docs.stimulusreflex.com/, but with a svelte backing instead of stimulus because. That said, stimulus reflex does look cool
|
# ¿ Feb 3, 2021 18:28 |
|
Gmaz posted:I use stimulus for non SPA purposes with my rails projects and I must say I really enjoy it. It's very simple to use, and anyone familiar with JS can pick it up super quickly. Even someone primarily backend oriented like me. Yeah, I just don't like working with the DOM like that. A well put-together React/Vue/Svelte project brings a lot of that Rails joy to the front end world, and Stimulus just doesn't do that for me.
|
# ¿ Feb 3, 2021 21:29 |
|
Yeah, there are definitely easy ways to screw up JS frameworks. Another former coworker is advocating for going in on React + GraphQL-Ruby
|
# ¿ Feb 5, 2021 00:14 |
|
Tea Bone posted:I'm trying to track the number of live users on my web app. Honestly, that kind of database overhead isn't bad at all. The other thing you might try is not deleting records, just keeping them around and updating sub/unsub dates. You could also go to a key:value store that might be a bit faster than postgres with the same benefits of having that on the DB.
|
# ¿ Mar 23, 2021 18:21 |
|
no question is too dumb for the rails love-in
|
# ¿ Jul 1, 2021 17:37 |
|
It was the wrong start script because the app is a React SPA with a rails API, not a traditional rails view app.
|
# ¿ Jul 2, 2021 17:27 |
|
2021 Rails has a few neat things that 2015 Rails didn't, and a few issues from 2015 rails still. Rails 5 launched in 2016, which brought with it the first signs of what modern Rails would be. It came with API-only and ActionCable, which is Rails's native websocket implementation. Both were much needed additions and filled out the feature set. Rails 6 launched with improvements to the JS environment, bundling webpacker with rails itself. I was trying to get them to go a little further and make it both easy to implement with a js bundler but also agnostic on which bundler you used. It's a little easier to swap out webpack with something else, but not where it should be. DHH's latest thing is Turbo, which is a front-end library that's supposed to feel more rails-y. I don't like it. OTOH, I do really like the combo library called Stimulus-Reflex, which creates a lite-js, front-end framework that actually does feel rails-y. I would consider it for greenfield projects going forward. Finally, there's my last annoyance: JSON generation is crap still. ActiveModel::Serializer has 3 active versions, each with annoying-enough-to-not-redo differences in usage. All versions are also slow as hell. Netflix abandoned FastJSONApi. Most of the others have been slow AF. The best I've found for 2021 Rails is a gem called Blueprinter. It's just a hair slower than Fast JSONApi, and more flexible. All that said: Rails is still a valid language and one of the fastest to get going on. But some of the more unique combos are catching up. I've recently become enamored with SvelteKit + Hasura as a Front/Back combo.
|
# ¿ Jul 27, 2021 20:51 |
|
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.
|
# ¿ Jul 28, 2021 16:36 |
|
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/
|
# ¿ Jul 28, 2021 17:42 |
|
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.
|
# ¿ Jul 28, 2021 18:32 |
|
|
# ¿ May 16, 2024 00:55 |
|
I've fully swapped over to TS on the whole stack for my own stuff. Between Next and Remix, it's just as straightforward for me to get going there as it is in Rails. I still like rails, but Remix is just as easy.
|
# ¿ Oct 10, 2023 15:27 |