/r/rails

Photograph via snooOG

A subreddit for discussion and news about Ruby on Rails

Looking for help?

Please make sure you've tried searching Google and StackOverflow.

If you still need help, please follow the rules in How do I ask for help?


Learning ruby/rails?

Scroll down a bit more for great learning resources.


Looking for a gem?

Please check out the links in the wiki before posting.

A subreddit for discussion and news about Ruby on Rails development

Posts about the Ruby programming language are encouraged to be posted in the /r/ruby subreddit.

Please message the mods if you would like to suggest changes to the sidebar.

Learning Ruby?

  • TryRuby in your browser
  • Try RubyKoans to learn more about syntax, structure, and common functions and libraries
  • Hackety Hack is a shoes app for playing around with ruby

Learning Rails?

Tools

Docs

  • APIdock: Rich and usable interface for searching, perusing and improving the documentation
  • Rails API: Searchable docs built with the sdoc gem.
  • rdoc: YARD Documentation Server
  • Ruby Doc: Complete and accurate documentation for the Ruby programming language
  • RelishApp Browsable Cucumber Features

Community

Rails jobs

Looking for work, or need to hire Rails developers?

Try /r/railsjobs, /r/forhire, or the following job sites:

/r/rails

64,881 Subscribers

26

Rails 8 is out so here's a brand new demo showing it off by building a basic blog, but adding authentication, PWA, and putting it into production with Kamal!

1 Comment
2024/11/14
21:53 UTC

3

ErrorGenie, my first gem and I am stuck hard!

Hello everybody,

I am trying to play around and come up with a silly little idea. I want to create a gem that, using your own key from OpenAI, will inject a new tab into the generic rails error page. The main idea is to add middleware and then intercept the error, capture it's body and add a tabbed navigation. (the error page and a page that, capturing all of the error detials, creates a gpt prompt with enviroment details, source code where the error happened) and it gives you a direct response.

I know it is very silly and my code here sucks, I am just trying to learn more, I would be interested in how would you capture the actual error details, as everything I tried seems to fail.

Thank you

https://github.com/rcbt17/errorgenie

1 Comment
2024/11/14
18:22 UTC

11

Difference between kamal-proxy and Thruster?

I can't figure out the difference between the two, despite reading quite a bit on the subject. Can someone help me out? Please feel free to ELI5. Thanks.

6 Comments
2024/11/14
17:06 UTC

4

Rails 8 and devcontainer : how to make "rails" again

Hello. I'm testing the possibility to use vscode, docker for remote developing.
I've built my test app:
rails new testapp --main --devcontainer

and rebuilt the dev container in vscode. All ok.

Now, i cannot use more "rails" command directly but i have to use "bin/rails". Is it a way to resolve this simple issue? I suppose it is enough to alias "rails" with "bin/rails" but i don't want to create problems with remote test.

Any suggestions?

Edit: in remote desktop, i can use rails and ruby without problems... so weird.

7 Comments
2024/11/14
16:13 UTC

6

Transcription app development

Hey, this is an interface for a transcription mobile application I'm working on. I'm using #Rails, #TailwindUI, and #StimulusJS, and I'm very excited about how much complexity compression these tools offer to build complex interactions. Check it out: youtu.be/ZaJWZFuw4oQ

0 Comments
2024/11/14
14:20 UTC

0

I'm very interested to see how Campfire is written. Help needed

I'm 19 years old, I've been writing in Rails for a year and I'm very interested to see the practices of 37 signal. Unfortunately my salary doesn't allow me to buy the source code, I earn little money (very small country and I can't move, I have to stay here for a few more years). Please if anyone can share, write me in private messages, I will not distribute or host, only for study purposes

6 Comments
2024/11/14
13:25 UTC

2

Is there a alternative to “rails app:template” for non-rails projects?

I have a set of instructions for integrating different tooling into my Ruby gem projects. This consists of about a dozen recipes for integrating and configuring tools such as YARD, SimpleCov, etc.

These recipes consist of a documentation page with manual instructions.

I’d like to change these to executable recipes that can be applied to a project by running a single command.

Rail application templates looks like what I want, but it does not seem to run outside of Rails.

Is there a tool equivalent to “rails app:template” that works for non-Rails projects?

I'd like to see what is out there before building my own (probably on top of Thor::Actions.

4 Comments
2024/11/13
22:54 UTC

15

Learning Rails + Turbo and loving it

Since beginning to learn rails two weeks ago I’ve had a blast leveraging Turbo to build out my SPAs.

I recently rewrote https://url2sheet.xyz/ in rails and am really happy with the process and outcome.

If anyone has feedback or questions I’d be happy to share my experience. Thanks!

2 Comments
2024/11/13
21:54 UTC

3

[Career Advice] How to approach the mentoring aspect in senior engineering interviews?

I could really use some advice from experienced developers. I've been working with Rails for about 3 years, mostly building APIs and distributed systems. While I'm confident in my technical abilities (built a few complex systems from scratch, led some interesting projects), I'm getting interviews for senior/staff positions that emphasize mentoring junior devs.

Here's the thing - I'm only 25, and while I've done code reviews and guided some interns, I honestly see myself more as a mid-level engineer who's still learning. But the job market seems to be pushing me towards senior roles.

I have an upcoming interview for a really exciting position, and I know they'll ask about mentoring experience (they always do). I want to be honest about my level while showing I'm capable of growing into that mentor role.

For those of you who transitioned from technical contributor to mentor:

  • What qualities make a good technical mentor?
  • How did you approach mentoring when you were first starting out?
  • Any tips for discussing this in interviews when you have limited experience?

Thanks in advance!

3 Comments
2024/11/13
21:11 UTC

5 Comments
2024/11/13
20:02 UTC

19

Advice on "setting up the world" in an RSpec test

I'm very familiar with using Factory Bot and I make extensive use of it in my test suite. However, as my application has grown, I find myself needing to create a lot of data (that is related to other data) in order to "set up the world" which makes the tests difficult to read when it grows to 30-50 lines of setup code.

I can think of a few different solutions to this problem, but I'm curious to hear others' opinion on this topic. The following are some contrived examples, but hopefully they illustrate the issue.

One approach is to use fixtures, except that fixtures aren't meant to be configured, and they become cumbersome when you have to name each scenario but only a small piece of information is changing between them.

Another approach is to make use of RSpec's let in order to make each little bit configurable. However, that also means that I need to structure my tests so that each context block has a let which overrides the value, which adds some extra lines for every test.

let!(:sprocket) do
  create :sprocket,
    user: user,
    foo: foo,
    bar: bar,
    sprocket_thing: sprocket_thing
end
let(:sprocket_thing) { nil }

context "when sprocket has a thing" do
  let(:sprocket_thing) { "foo" }

  it "returns the correct value" ...

Another approach is to make use of transients so that you can pass unrelated options to the associated models. This is nice in some small cases, but it becomes unsustainable when you start having too many options or relationships to set up.

FactoryBot.define do
  factory :user do
    association :foo

    transients do
      sprocket_options { nil }
    end

    after(:build) do |user, options|
      if options.sprocket_options
        build(:sprocket, user: user, **sprocket_options)
      end
    end
  end
end

context "when sprocket has a thing" do
  it "returns the correct value" do
    foo = create :foo
    bar = create :bar, foo: foo
    ...
    user = build(:user, foo: foo, sprocket_options: {
      foo: foo,
      bar: bar,
      sprocket_thing: "foo"
    })
    ...

And yet another option is to define a custom method that only exists in the test to set up the data. However, I wonder how to design this in a way that I can reference some of the generated data without using instance variables.

def setup_the_world(sprocket_thing: nil)
  foo = create :foo
  @bar = create :bar, foo: foo
  user = create :user, foo: foo
  create(:sprocket,
    user: user,
    foo: foo,
    bar: @bar,
    sprocket_thing: sprocket_thing || "default value")
end

context "when sprocket is normal" do
  it "returns the correct value" do
    setup_the_world

    expect(subject.bar).to eq @bar
  end
end

context "when sprocket has a thing" do
  it "returns the correct value" do
    setup_the_world(sprocket_thing: "foo")

    expect(subject.bar).to eq "foo"
  end
end

What is your preferred way of setting up a large amount of data in your test?

17 Comments
2024/11/13
19:57 UTC

14

System Design: Learn by creating a Scorer System // Software Architecture and Implementation Example

1 Comment
2024/11/13
15:19 UTC

5

Looking for a blog post about ruby block and how it's used as a design in gem

I am pretty sure I found a blog post here on how gem author use blocks to design their api. It was using ActiveRecord::transaction as a starting point and then explained how you could use a similar approach in your own code. But I can't find in now, does that ring any bell ?

2 Comments
2024/11/13
10:08 UTC

3

Help understanding when to use turbo_frame_tags if we can update the DOM using Turbo Streams without them

In my Rails app we have Users and Tutorials. Users can save Tutorials. The user has a button on a tutorial listing that they can click which will save it to their tutorials.

Here's some code in a partial I'm rendering that the user clicks to save the tutorial:

<div id="<%=dom_id(tutorial, "save")%>">
  <%= button_to "Save", saved_tutorials_path,
              params: { saved_tutorial: { tutorial_id: tutorial, user_id: current_user } } %
</div>

In my controller I call a service, and then render a Turbo Stream response. The view for the saved_tutorials_path looks like this:

<%= turbo_stream.update dom_id(@saved_tutorial.tutorial, "save") do %>
  <%= button_to "Saved!", saved_tutorials_path,
                    params: { saved_tutorial: { tutorial_id: @saved_tutorial.tutorial.id, user_id: current_user } } %>
<% end %>

Ultimately all I'm doing is updating the "Save" text to "Saved!". If the user clicks the "Saved!" button, then they will un-save the tutorial.


My question is why do we need to use turbo_frame_tag if we can seemingly do what we need to do without them? I've just updated the DOM directly entirely on the server without using a Turbo Frame tag anywhere.

For building SPA-style functionality in Rails apps, when should we use turbo_frame_tag and when should we do what I've done in the example above?

4 Comments
2024/11/13
09:36 UTC

5

Two-level multi-tenancy structure in Rails

How can I build a two-level multi-tenancy structure in Rails where I have multiple Organizations, and each Organization has multiple session_years? I need to ensure that data within one session_year is completely isolated from other session_years within the same Organization, and that session_years are also isolated across different Organizations. What would be the best approach to structure my models, associations, and scoping to achieve this data isolation? Also, are there any best practices or gems that could simplify implementing this structure?

5 Comments
2024/11/13
06:16 UTC

4

Seeking dev to help upgrade a small Rails app

Hi folks,

I'm looking for a dev to help upgrade an app from Rails 6.0.4 on Ruby 3.0.1 to current Rails 7 on the appropriate Ruby version. App runs on Heroku (currently the 20 stack, which is being deprecated soon, so we want to move to the 24 stack).

Code quality is pretty good - RubyCritic rated it 91.58 out of 100.

Looking to get this upgrade started fairly quickly, ideally. Test coverage is less than ideal (~35%) but as mentioned the app is fairly simple, and the owner is happy to help with testing along the way.

I have a report from a local company details their audit findings, which I'm happy to share. If you're interested, please DM with your info (experience, availability, rate etc), and I'll share this report for you to provide an estimate.

Thanks to the awesome community!

10 Comments
2024/11/13
04:09 UTC

5

Performance tracking of Rails apps

Does Ruby on Rails have a gem to keep track of performance of your app?

For reference, there's Pulse for Laravel:
https://pulse.laravel.com/

12 Comments
2024/11/13
01:25 UTC

1

How Can I Create an AI Tool Like Crayo.ai for Generating Videos?

I've been fascinated by AI tools like Crayo.ai, Veed.io, that generate videos based on text prompts, and I'm interested in building something similar. I have experience in software development but would like some guidance on where to start.

0 Comments
2024/11/13
00:37 UTC

22

Where can I find Rails freelancers?

I'm planning to start a few Rails projects in the coming months and would like to find some freelancers in the Western Hemisphere (for timezone reasons) who can help. Are there any good resources to find talented Rails devs?

33 Comments
2024/11/12
21:40 UTC

16

A search engine for all your memes - built with Rails

The open source engine indexes your memes by their visual content and text, making them easily searchable. Auto generate or manually create descriptions for your memes and tag them for easy recovery.

Find your funny fast, then drag & drop recovered meme(s) into any messager.

Note: local install requires >= 7gb of storage due to the size of AI model weights. It consists of three docker containers - the app, postgres db, and meme description generator.

Rails is a fantastic framework for building / iterating on "AI-powered" apps like this one.

See the project here 👉 https://github.com/neonwatty/meme_search

Uses gems like nieghbor, informers, and pgvector under the hood. As well as local calls to moondream, a "tiny" vision language model.

0 Comments
2024/11/12
13:06 UTC

4

Devise confirmation emails end up in spam folder

I am using Devise for handling authentication and I guess this is most of us - rails devs - do and not anything surprising.

I also use a local company's email service and we had pretty much no problems until past few weeks I realized confirmation emails end up in spam folder specially when the recipients are using Gmail.

Now, the support team of the local mail server company told me that the content of the email matters. I am asking here, did you have similar situations? And how did you solve that?

P.S : They have set a lot of headers and anti-spam stuff in their configurations. I checked it a few times in past 48 hours.

7 Comments
2024/11/12
12:14 UTC

125

Why I’m Advising Clients to Ditch Rails APIs + JS Frontends for Pure Rails

I’ve started recommending a pure Rails stack for new projects instead of the typical Rails API + JS frontend setup. After years of working with React, Vue, and Angular (for the record, Vue is my favorite), I’m finding the simplicity of pure Rails hard to beat, especially when there aren’t complex frontend requirements.

For projects where you don’t need fancy frontend interactions or heavy JS libraries, Rails alone can get the job done faster and with less hassle. The main drawback? Rails doesn’t have the robust JS library support needed for things like visual editors (e.g., Puck) or other advanced interactions.

Curious if anyone else is feeling the same way?

58 Comments
2024/11/11
21:41 UTC

16

Best country to move to as a Rails Dev?

What's the best country to move to as a Rails developer?

For context, I'm from Zimbabwe(Africa) I'm about to finish my bachelor's and I'm looking for countries where Rails is popular as tech stack, which are not the US

I've been using Laravel for a while but switched to Rails and I love it and would like to use it professionally at a dev shop or a product company

Then my question now is where is Rails popular around the world

24 Comments
2024/11/11
20:04 UTC

5

Best Way to implement Oauth authentication & Authorization

I am developing a application from scratch and our team has decided to go with Oauth authentication and autherization. The application has react frontend and it also needs to do s2s communication. Rails implementation of Oauth is with doorkeeper along with devise. Another approach we were discussing heard was using another server separately for outh like passport(Laravel framework) or other Go open source implementation.

I want to go with doorman with devise implementation. Has anyone used this approach? Is doorkeeper robust and reliable enough to handle all the cases of Oauth? Is there any pros and cons attached to using this approach?

5 Comments
2024/11/11
17:07 UTC

Back To Top