Skip to main content

Get the Reddit app

Scan this QR code to download the app now
Or check it out in the app stores
r/rails icon
r/rails icon

r/rails

members
online



Shadcn-rails vs PhlexUI Shadcn-rails vs PhlexUI

I'm a backend software engineer with 2 years of experience.

Recently I have been working on a small rails project. This is the first time that I need to write major frontend code. Although Hotwire makes it easy to create reactive(ish) UI, I still need a few highly interactive components.

I'm looking to use shadcn-rails or phelx_ui to do the job. From what I could tell, phelx_ui looks much easier to use, but has many components missing, while shadcn-rails is a more complete solution.

Still, I wanted to get opinion from folks who have more experience working on frontend technologies in rails.

Thanks




Could someone help me? My rails app worked fine locally but the SortableJS functions didn't work when it was deployed through Heroku. I made changes to it to try and fix it but now it doesn't work locally. I am fucked Could someone help me? My rails app worked fine locally but the SortableJS functions didn't work when it was deployed through Heroku. I made changes to it to try and fix it but now it doesn't work locally. I am fucked

I used 'RAILS_ENV=production bundle exec rake assets:precompile .' from this answer 'https://stackoverflow.com/questions/10945809/why-is-javascript-not-working-on-deployment-to-heroku' , creating secretkey etc. I went back to my original commit where it worked but it's not working. If you could help me DM me for my github because it has my name in it. Please it's very basic!




Ensuring uniqueness of values in two columns Ensuring uniqueness of values in two columns

I have a scenario of a users table with a phone_number column and an alternate_phone_number column. Is there a rails way of ensuring uniqueness of a number in both columns? (As in if the number is already in column one it can’t be saved in column two and vice-versa). I already have a unique index for each column. Do I just look up the number in the other column before trying to save or is there a built in way of doing this?




Video Processing in Ruby/Rails Video Processing in Ruby/Rails

I'm working on a small rails project, where I need to do some video processing in background jobs (ActiveJob with SolidQueue), and then upload the rendered video to S3 using Active Storage.

The problem is, I couldn't find any up to date video processing Ruby gems like ffmpeg, opencv etc.

I'm left with using Python for video processing (moviepy), but am struggling with integrating the whole flow with ActiveJob and ActiveStorage.

Have you guys faced such issues? What do you suggest I should do?

Thanks




Should I use Ubuntu or Mac OS for Rails development? Should I use Ubuntu or Mac OS for Rails development?
Help

I've never picked a work laptop myself, but my Mac broke recently, so I have to. I programmed on Ubuntu a bit when I was an intern but then I was added to a project that required Mac, so I've been developing on Mac OS for the past two years. What do you guys use? The project I work on is quite old and undockerized, so some people had a lot of trouble installing it on new Apple chips, but I doubt that Ubuntu installation is smooth as well.


Question about GraphQL queries (not mutations) Question about GraphQL queries (not mutations)

Below is one off the GraphQL queries in use for our API.

I need to know if it's possible for a Query, not mutation, to have multiple types.

Do I just use field instead of type?


module Queries
  class FetchLobbyCount < Queries::BaseQuery
    graphql_name "FetchLobbyCount"

    argument :user_id, Integer, required: false

    type Integer, null: false

    def resolve(user_id:)
      @user = User.find(user_id)

      unless @user.present?
        return GraphQL::ExecutionError.new("Cannot find user with id: #{user_id}")
      end

      User.where(awaiting_match: true).where.not(id: user_id).count
    end
  end
end

Validation of uniqueness of boolean attribute on nested has_many object Validation of uniqueness of boolean attribute on nested has_many object

Struggling with such a simple thing, I just wanted to ask and see if there's a solution or in 2024 this is still not possible.

Here's the pseudocode:

class Parent
  has_many :children
  accepts_nested_attributes_for :children
end

class Child
  validates :primary, inclusion: { in: [true, false] }, uniqueness: { scope: :parent, if: :primary? }
end

I want to ensure that only one child is marked primary when I update parent with nested child records. The uniqueness validation in the pseudocode does not work because it fails when changing primary's Child A to Child B, because it doesn't look at the pending nested objects' pending changes but instead the currently persisted nested objects. The other approach I saw was to use a custom validation in the Parent class, but I can't seem to use Dirty methods or access the pending changes at all.

Answers I don't need: Just rely on a database index, do the validation by accessing the params in the controller, add a column on parent for `primary_child_id`. This is less about getting to the end result and more about whether there is a tool to elegantly achieve this in the model the way it should be possible.



How to get navbar to change after devise sign in How to get navbar to change after devise sign in
Help

I have a navbar (in layout) with a button to the devise sign in and once it’s signed in, it goes back to the homepage and the button in the navbar is supposed to be a sign out button now. But, it’s not. However, rails does recognize that the user_signed_in is true because I put a if statement in the homepage view to say “signed in” if it’s signed in and it shows without refreshing. But, I need to refresh the page for the navbar button to change.

I’m really not sure how to fix this and couldn’t find much online about my specific problem.


Possible to get rails session info from redis store before ActionDispatch initialises session? Possible to get rails session info from redis store before ActionDispatch initialises session?
Help

Hi, I have a rails web app. I am trying to log user_id for every log line through log tag. We use devise/warden for auth, so if we had cookie store, code like attached below would work. But we use redis store.

Any ideas on how to access the actual session since ActionDispatch isn't actually initialised at the point of configuring log tags?

Rails 7, Ruby 3.

https://preview.redd.it/possible-to-get-rails-session-info-from-redis-store-before-v0-hs3k3ek3pmfd1.png


Rails IDEs Autocomplete Rails IDEs Autocomplete
Question

I am currently looking at IDEs and have so far used VScode with a bit of success. I am looking for more features though and want to know what IDE / plugins you recommend for it:

  1. Autocomplete and I mean „good“ autocomplete, including my ActiveRecord fields

  2. Usage search - pretty standard feature in most languages in the „big“ IDEs but i could not get it to work with rails

  3. Good erb support. If I have a button I would like to be able to get the action suggested instead of remembering the whole name (+ usage search if possible). Also I would love to have autoformatting which is clunky for me rn

Thanks for any input



eager loading relationships in a sidekiq job eager loading relationships in a sidekiq job

EDIT: resolved. The problem is that the code has some funky stuff with a transaction that was preventing the behavior I expected.

I have a sidekiq job that eager loads records, iterates over them and passes the record to another class.

For some reason the records are _not_ being eager loaded in the second class.

I swear I've done this before and it should work but it's not?

Here's some pseudo code to replicate the setup:


class MyJob
  include Sidekiq::Job
  def perform
    Model.includes(:relationships).each do |model|
      # the puts and loaded? are just for debugging
      puts "relationships loaded? #{model.relationships.loaded?}"
      # => relationships loaded? true
      OtherClass.new(model).call
    end
  end
end

class OtherClass
  def initialize(model)
    @model = model
  end

  def call
    # the puts and loaded? are just for debugging
    puts "relationships loaded? #{@model.relationships.loaded?}"
    # => relationships loaded? false
  end
end