I notice in Rails tutorials sometimes the authors make helper methods that are only used one time. This strikes me as ridiculous but while learning ActionCable I noticed that DHH did the same thing in his introduction for ActionCable 2 years ago. So maybe there is a point to it that I am missing. Just for illustration, here is the code from DHH.
# app/jobs/message_broadcast_job.rb
class MessageBroadcastJob < ApplicationJob
queue_as :default
def perform(message)
ActionCable.server.broadcast 'room_channel', message: render_message(message)
end
private
def render_message(message)
ApplicationController.renderer.render(partial: 'messages/message', locals: { message: message })
end
end
Now I would just write the perform method something like this, and skip the helper method:
def perform(message)
ActionCable.server.broadcast 'room_channel', {
message: ApplicationController.renderer.render(
partial: 'messages/message',
locals: { message: message }
)
}
end
Is there any benefit to the first structure over mine? I only see a pointless abstraction.